简体   繁体   中英

Buttons getting cut off in landscape rotation (Android XML)

When I rotate my screen to landscape mode, a DialogFragment containing this layout is cutting off the two buttons at the bottom:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:padding="4dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Alias"/>

    <EditText
        android:id="@+id/edittext_alias"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textCapWords"
        android:ems="10"
        android:layout_marginLeft="4dp"
        android:maxLength="30"
        android:imeOptions="actionDone"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Interests"/>

    <EditText
        android:id="@+id/edittext_interests"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="text"
        android:ems="10"
        android:layout_marginLeft="4dp"
        android:maxLength="10"
        android:imeOptions="actionDone"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Bio"/>

    <EditText
        android:id="@+id/edittext_bio"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textCapSentences"
        android:ems="10"
        android:layout_marginLeft="4dp"
        android:maxLines="2"
        android:gravity="top"
        android:imeOptions="actionDone"
        android:requiresFadingEdge="vertical"
        android:fadingEdgeLength="20dp"
        android:scrollbars="vertical"
        android:fadeScrollbars="false"/>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/button_cancel"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="Cancel"
            android:layout_weight="1"/>

        <Button
            android:id="@+id/button_confirm"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="OK"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1"/>
    </LinearLayout>

</LinearLayout>

Am I doing something wrong or missing something obvious? How can I get it to force display everything?

I think the case is your screen is simply not large enough to show the whole content. Android does not add the scroll functionality if content is larger then the screen. If this is the case wrap all your views in a ScrollView so that the buttons could be visible after scrolling. Like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:padding="4dp"> 

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <!-- Putt all your view here -->

        </LinearLayout>
    </ScrollView>
</LinearLayout>

Also you may put ScrollView as Your Parent View

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <!-- Putt all your view here -->

        </LinearLayout>
    </ScrollView>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM