【问题标题】:Android ScrollView doesn't work correctly in landscape modeAndroid ScrollView 在横向模式下无法正常工作
【发布时间】:2015-11-09 18:38:51
【问题描述】:

我的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。帮我解决这个问题??我是新手。

【问题讨论】:

    标签: android xml android-scrollview


    【解决方案1】:

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

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

    【讨论】:

    • RESET 按钮在横向模式下的位置与纵向模式不同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-24
    • 1970-01-01
    • 1970-01-01
    • 2016-01-09
    • 1970-01-01
    • 2020-05-15
    • 1970-01-01
    相关资源
    最近更新 更多