我的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/