当我使用 android:layout_alignParentBottom="true"
时,我的RelativeLayout中有一个按钮正被切断,但我尝试的其他任何东西都没有正常工作 . 有任何想法吗?
这是我的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.cdar.sab.cdar.MainActivity$PlaceholderFragment">
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/diagnostics_title" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:layout_below="@+id/section_label"
android:layout_alignParentStart="true"
android:layout_marginTop="42dp"
android:hint="@string/email_hint"
android:id="@+id/emailTB" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:layout_below="@+id/emailTB"
android:layout_alignParentStart="true"
android:layout_marginTop="45dp"
android:hint="@string/message_hint"
android:maxLines="10"
android:id="@+id/messageTB" />
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button"
android:layout_alignParentBottom="true" />
</RelativeLayout>
9 回答
很难理解为什么UI会被扭曲,原因可能有很多,但我非常怀疑文本的限制是否会超出导致UI失真的输入框中 . 请添加屏幕截图以便更好地理解所以根据它,我试图减少视图之间的文本大小和边距,以确保UI不会扭曲,如果这是由于几个边缘 .
您已在主容器中指定了布局填充
添加边距而不是填充将解决您的问题 . 尝试下面的代码
请添加屏幕截图以更好地理解问题,如果按钮的一半隐藏在屏幕导航栏后面(因为某些设备有屏幕导航栏和屏幕外的其他设备),然后在RelativeLayout
android:fitsSystemWindows="true"
中添加此行,或者您可以使用代码隐藏导航栏 .我使用LinearLayout修改了你的布局,希望它对你有用 .
我看到你在PlaceholderFragment中使用了布局 . 我在片段中的适配器遇到了同样的问题 . 您应该尝试使用第二个EditText约束按钮,然后运行代码(快速修复) . 我认为问题在于,当您在片段中运行代码时,布局会被移位,并且match_parent将被计算为整个屏幕(或活动的大小),从而将按钮与父Activity对齐,然后将布局向下移动以腾出空间对于标签标签 .
The layout looks fine
希望这会有所帮助:
您需要为Button添加外部相对布局
也许你可以尝试将marginBottom给你的Button