簡體   English   中英

橫向旋轉時按鈕被切斷(Android XML)

[英]Buttons getting cut off in landscape rotation (Android XML)

當我將屏幕旋轉到橫向模式時,包含此布局的DialogFragment切斷了底部的兩個按鈕:

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

我是在做錯什么還是錯過了明顯的事情? 我如何才能強制顯示所有內容?

我認為情況是您的屏幕根本不夠大,無法顯示全部內容。 如果內容大於屏幕,則Android不會添加滾動功能。 在這種情況下,將所有視圖包裝在ScrollView以便在滾動后可以看到按鈕。 像這樣:

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

您也可以將ScrollView用作父視圖

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM