Android ScrollView 在横向模式下无法正常工作

标签 android xml android-scrollview

landscape mode image of the app

portrait mode image of the app

我的xml代码-->>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    tools:context=".MainActivity" >

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

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

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/team_a"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:padding="16dp"
                    android:text="@string/team_a" />

                <TextView
                    android:id="@+id/team_a_score"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:padding="16dp"
                    android:text="@string/team_a_score"
                    android:textSize="56sp" />

                <Button
                    android:id="@+id/three_but"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="24dp"
                    android:layout_marginRight="24dp"
                    android:layout_marginTop="8dp"
                    android:background="#ff9800"
                    android:onClick="addThreeForA"
                    android:text="@string/three_but"
                    android:textAllCaps="true" />

                <Button
                    android:id="@+id/two_but"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="24dp"
                    android:layout_marginRight="24dp"
                    android:layout_marginTop="8dp"
                    android:background="#ff9800"
                    android:onClick="addTwoForA"
                    android:text="@string/two_but"
                    android:textAllCaps="true" />

                <Button
                    android:id="@+id/one_but"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="24dp"
                    android:layout_marginRight="24dp"
                    android:layout_marginTop="8dp"
                    android:background="#ff9800"
                    android:onClick="addOneForA"
                    android:text="@string/one_but"
                    android:textAllCaps="true" />
            </LinearLayout>

            <View
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:layout_marginTop="16dp"
                android:background="@android:color/darker_gray" />

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/team_b"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:padding="16dp"
                    android:text="@string/team_b" />

                <TextView
                    android:id="@+id/team_b_score"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:padding="16dp"
                    android:text="@string/team_b_score"
                    android:textSize="56sp" />

                <Button
                    android:id="@+id/three_but_b"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="24dp"
                    android:layout_marginRight="24dp"
                    android:layout_marginTop="8dp"
                    android:background="#ff9800"
                    android:onClick="addThreeForB"
                    android:text="@string/three_but_b"
                    android:textAllCaps="true" />

                <Button
                    android:id="@+id/two_but_b"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="24dp"
                    android:layout_marginRight="24dp"
                    android:layout_marginTop="8dp"
                    android:background="#ff9800"
                    android:onClick="addTwoForB"
                    android:text="@string/two_but_b"
                    android:textAllCaps="true" />

                <Button
                    android:id="@+id/one_but_b"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="24dp"
                    android:layout_marginRight="24dp"
                    android:layout_marginTop="8dp"
                    android:background="#ff9800"
                    android:onClick="addOneForB"
                    android:text="@string/one_but_b"
                    android:textAllCaps="true" />
            </LinearLayout>
        </LinearLayout>

        <Button
            android:id="@+id/reset"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="200dp"
            android:layout_marginBottom="16dp"
            android:background="#ff9800"
            android:onClick="resetAll"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:text="@string/reset"
            android:textAllCaps="true" />
    </RelativeLayout>

</ScrollView>

当应用程序处于纵向模式时,scrollView 可以正常工作,但当它处于横向模式时,scrollView 可以正常工作,但重置按钮不会像纵向模式那样保持在底部位置。我怎么解决这个问题? 此外,RelativeLayout 的属性 layout_height = "match_parent"显示警告,它应该是 wrap_content。帮我解决这个问题??我是新手。

最佳答案

ScrollView 不能很好地与 RelativeLayout 配合使用,请使用

<Scrollview> 
    <LinearLayout>
        <RelativeLayout>
        **everything else**
        </RelativeLayout>
        <Button .. />
    </LinearLayout>
</Scrollview>

关于Android ScrollView 在横向模式下无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33615897/

相关文章:

android - 抽屉导航Recycler View null指针异常

java - 使用 getNodeValue() 获取文本和内联元素

xml - 从 xml 文件中提取特定字段

android - maxSdk的权限显示为Play商店上每个应用程序更新的新权限

java - 为什么甚至在点击上传按钮 Android Firebase Storage 之前图像就会自动上传?

java - 在着色器中使用 alpha 测试的 OpenGL ES 2.0 透明度

Android NestedScrollView TalkBack - 仅导航到屏幕上可见的项目,跳过滚动下方的元素并转到底部选项卡

JAVA:两步 View 模式:我们如何使用两个 XSL 文件将转换 View 转换为两步 View 以获得所需的 HTML 输出?‽

Android水平 ScrollView 像画廊

具有固定页眉和页脚的 ScrollView 内的 Android 相对布局