如何解决Android Studio 小部件在相对布局中消失了
为什么相对布局会使我的小部件消失。每当我在代码中添加编辑文本时,一切都会消失。
<RelativeLayout
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"
tools:context=".userconfirmation">
<ImageView
android:id="@+id/imageView"
android:layout_width="120dp"
android:layout_height="150dp"
android:layout_marginTop="40dp"
app:srcCompat="@drawable/ic_house"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="70dp"
android:layout_centerInParent="true"
android:layout_above="@+id/editTextemail"
android:text="Login"
android:textColor="@color/black"
android:textSize="30sp" />
<EditText
android:id="@+id/editTextemail"
android:layout_width="250dp"
android:layout_height="40dp"
android:ems="10"
android:hint="Email"
android:inputType="textPersonName"
android:textSize="16dp"
android:background="@color/light_grey"
android:layout_marginBottom="35dp"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true" />
</RelativeLayout>
当我添加这个小部件时,在相对布局中,它们突然消失了。是什么原因?
解决方法
只需从 TextView 属性中删除以下行
android:layout_above="@+id/editTextemail"
,
确保使用从 top 到 bottom 的 ID,反之亦然。
改变这个
android:layout_above="@+id/editTextemail"
到
android:layout_below="@+id/imageView"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。