嵌套布局ScrollView

时间:2014-02-19 22:14:10

标签: android android-tablelayout

我一直在努力解决这个问题,到目前为止一直无法找到答案。 我在RelativeLayout中有一个TableLayout。我需要TableLayout可滚动,而不是相对布局,因为它有静态按钮我不打算移动它们。

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:layout_weight="1">
     <RelativeLayout 
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Encuestas" >
     <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginRight="14dp"
    android:layout_marginTop="14dp"
    android:onClick="SyncServer"
    android:text="Sync" />

         <TableLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:id="@+id/TableLayout1"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/button1" >

        </TableLayout>


 </RelativeLayout>
</ScrollView>

使用此代码我可以滚动整个屏幕,但如果我尝试将ScrollView放在TableLayout上,我就无法点击我创建的按钮。

 <RelativeLayout 
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:id="@+id/RelativeLayout1"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".Encuestas" >

  <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginRight="14dp"
    android:layout_marginTop="14dp"
    android:onClick="SyncServer"
    android:text="Sync" />
   <ScrollView

  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:scrollbars="vertical"
  android:layout_weight="1">
  <TableLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:id="@+id/TableLayout1"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/button1" >


 </TableLayout>

  </ScrollView>
   </RelativeLayout>

这个不允许我点击按钮。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

永远不要将可滚动视图放在另一个可滚动视图中(滚动方向相同)。这个规则的唯一例外是当主出现在你面前的所有荣耀和手中时,你的石碑上刻着一些其他的东西。

无论如何,第二个布局可以使用一个小修改,你必须告诉布局将scrollview放在按钮下面,如下所示:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"
    android:layout_below="@id/button1"
    android:layout_weight="1">