GUI元素无法正常显示

时间:2017-03-05 18:53:18

标签: android user-interface

当我遇到以下问题时,我正在关注Youtube上的一些Android教程: (离开设计师,右边是模拟器) enter image description here

我尝试在谷歌搜索,但似乎无法找到正确的链接。 有谁知道发生了什么事?我尝试删除并放置新元素,但同样的问题仍然存在。

[编辑] 我没有改变的XML代码。这是用一个新项目创建的。 enter image description here 图片中的所有元素都被拖放。没有代码被更改。

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="visible"
    tools:context="com.example.todor.myapplication.MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:layout_editor_absoluteX="159dp"
        tools:layout_editor_absoluteY="235dp"
        tools:text="@string/loginbutton" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="132dp"
        android:layout_height="31dp"
        android:layout_marginBottom="42dp"
        android:fontFamily="monospace"
        android:textAlignment="center"
        android:textColor="@color/colorAccent"
        android:textColorHint="@android:color/holo_blue_bright"
        android:textStyle="bold"
        android:visibility="visible"
        app:layout_constraintBottom_toTopOf="@+id/editText"
        tools:text="@string/logintext"
        tools:layout_editor_absoluteX="126dp" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="33dp"
        android:width="300dp"
        android:ems="10"
        android:hint="@string/emailhint"
        android:inputType="textEmailAddress"
        app:layout_constraintBottom_toTopOf="@+id/editText2"
        tools:layout_editor_absoluteX="42dp" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="40dp"
        android:width="300dp"
        android:ems="10"
        android:hint="@string/passowrdhint"
        android:inputType="textPassword"
        app:layout_constraintBottom_toTopOf="@+id/button"
        tools:layout_editor_absoluteX="42dp" />
</android.support.constraint.ConstraintLay

出&GT;

1 个答案:

答案 0 :(得分:1)

以下是一些提示!

了解 Tools Attributes Reference

Android Studio支持工具命名空间中的各种XML属性,启用设计时功能(例如在片段中显示哪种布局)或编译时行为(例如缩小模式)应用于您的XML资源)。构建应用时,构建工具会删除这些属性,因此对您的APK大小或运行时行为无效

您需要了解以下属性的区别!

tools:text="loginbutton"
android:text="loginbutton"

您的观点不受约束他们只有设计时间位置! 转到设计,拖动角落直到圆圈变为绿色,然后给出约束。这是与ConstraintLayout相关的linkOne LinkTwo的额外指导

如果你把它弄得很糟糕,你可以用android.support.constraint.ConstraintLayout替换LinearLayout,但这不是解决方案,而是另一种方式!