Java 与相对线底部对齐的按钮被切断

Java 与相对线底部对齐的按钮被切断,java,android,android-relativelayout,Java,Android,Android Relativelayout,当我使用android:layout\u alignParentBottom=“true”时,我的RelativeLayout中有一个按钮被切断,但我尝试的其他任何东西都不能正常工作。有什么想法吗 以下是我的布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:l

当我使用
android:layout\u 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>

也许你可以试着给你的按钮加上marginBottom

 android:layout_marginBottom="8dp"
<RelativeLayout..............>
    <RelativeLayout android:id="@+id/content_rl>
    <!-- Some ELEMENTS -->
    </RelativeLayout>

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/content_rl">

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Button" />
</RelativeLayout>

请添加一个屏幕截图以更好地理解问题,如果按钮的一半隐藏在屏幕导航栏后面(因为某些设备有屏幕导航栏,而其他设备则在屏幕之外),那么请在您的RelativeLayout
android:FitsystemWindows=“true”
中添加这一行,或者您可以使用代码隐藏导航栏

我使用LinearLayout修改了您的布局,希望它对您有用

<LinearLayout 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:id="@+id/emailTB"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="42dp"
        android:ems="10"
        android:hint="@string/email_hint"
        android:inputType="textEmailAddress" />

    <EditText
        android:id="@+id/messageTB"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="45dp"
        android:layout_weight="1"
        android:ems="10"
        android:hint="@string/message_hint"
        android:inputType="textMultiLine"
        android:maxLines="10" />

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0dp"
        android:text="Button" />

</LinearLayout>

您在主容器中提供了布局填充。即

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
添加边距而不是填充将解决您的问题

android:marginBottom="@dimen/activity_vertical_margin"
android:marginLeft="@dimen/activity_horizontal_margin"
android:marginRight="@dimen/activity_horizontal_margin"
android:marginTop="@dimen/activity_vertical_margin"

我看到您在占位符片段中使用了布局。我对片段中的适配器也有同样的问题。您应该尝试使用second EditText约束按钮,然后运行代码(快速修复)。我认为问题在于,当您在片段中运行代码时,布局会发生移动,匹配父项将作为整个屏幕(或活动的大小)进行计算,从而将按钮与父项活动对齐,然后向下移动布局,为选项卡标签腾出空间。
希望这会有所帮助:

<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">

<RelativeLayout
    android:id="@+id/rlContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/section_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/diagnostics_title" />

    <EditText
        android:id="@+id/emailTB"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/section_label"
        android:layout_marginTop="42dp"
        android:ems="10"
        android:hint="@string/email_hint"
        android:inputType="textEmailAddress" />

    <EditText
        android:id="@+id/messageTB"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/emailTB"
        android:layout_marginTop="45dp"
        android:ems="10"
        android:hint="@string/message_hint"
        android:inputType="textMultiLine"
        android:maxLines="10" />

</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/rlContainer">

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Button" />
</RelativeLayout>


您需要为按钮添加外部相对布局

 android:layout_marginBottom="8dp"
<RelativeLayout..............>
    <RelativeLayout android:id="@+id/content_rl>
    <!-- Some ELEMENTS -->
    </RelativeLayout>

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/content_rl">

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Button" />
</RelativeLayout>



很难理解为什么用户界面会失真可能有很多原因,但我高度怀疑的是,输入框中的文本超出了限制,从而导致用户界面失真。请添加屏幕截图以便更好地理解。因此,根据它,我试图减少文本大小和视图之间的边距,以确保UI不会因为边距太少而扭曲

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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">

<TextView
    android:id="@+id/section_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Diagnostic"
    android:textSize="12sp"/>

<EditText
    android:id="@+id/emailTB"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/section_label"
    android:layout_marginTop="22dp"
    android:ems="10"
    android:hint="Hint"
    android:inputType="textEmailAddress"
    android:textSize="12sp"/>

<EditText
    android:id="@+id/messageTB"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/emailTB"
    android:layout_marginTop="25dp"
    android:ems="10"
    android:hint="Hint"
    android:inputType="textMultiLine"
    android:maxLines="10"
    android:textSize="12sp"/>

<Button
    android:id="@+id/button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="Button" />

</RelativeLayout>



你说“切断”是什么意思?你能发布一些截图吗?是它根本就没有出现,还是一些边缘被切断了?@AnkitSharma我现在不能,但我明天也许可以。但基本上,这就好像视图延伸到了显示边界之外。只有按钮的顶端显示。其余部分已被切断。您的布局正常。请发布截图。请添加截图,您的视图可能会由于EditText或TextView中的大文本而扭曲。为了更好,您可以将ScrollView用作根视图。问题是,所有屏幕大小的间距都不匹配。我将尝试添加android:fitsystemwindows=“true”,然后再与您联系。谢谢我会尝试一下,看看这是否是我需要做的改变。谢谢不如让EditText的0dp高度和布局权重=1,在EditText和按钮之间插入一个普通视图,0dp高度和布局权重=1。不是100%确定,但我认为您的解决方案会导致EditText文本放置在视图的底部或中心,这可能看起来很奇怪。我的解决方案适用于我,即使使用可变高度的对话框,例如,如果它包含一个可扩展的列表。我只是不确定如何在所有不同的屏幕大小上保持它与底部对齐。这不起作用。它只是让间距变得非常奇怪。这在布局预览中看起来不错,但在我将其加载到设备上时,它与我的问题相同。尝试为具有按钮的相对布局提供底部空白。这与预期效果相同。对于我目前正在设置边距的设备来说,它看起来不错,但其他屏幕尺寸将不一样。我需要在屏幕大小上保持一致。这和Inderpret Singh说的一样,但它没有正常工作。谢谢。在my textview中更改文本大小可以使视图适合屏幕内部。