2014-02-19 174 views
1

我一直在努力这一段时间,迄今一直无法找到答案。 我在RelativeLayout中有一个TableLayout。我需要TableLayout是可滚动的,而不是相对布局,因为它有我不打算移动的静态按钮。嵌套布局ScrollView

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

有了这个代码,我可以滚动整个屏幕,但如果我尝试把对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> 

这一次不允许我点击的按钮。有什么建议么?

+0

我认为这可能是由于这样的事实,'ScrollView'正在被添加到'Button'之后的布局中,并被配置为匹配父级的高度和宽度,因此它位于z-index中的“Button”之上。尝试在'ScrollView'后添加'Button'。 –

+0

谢谢Manveer Chawla。我忘了ScrollView在按钮前面。 –

+0

如果这对你有用,我应该发布这个答案吗? :) –

回答

1

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

无论如何,第二布局将有一个小的修改工作,你必须告诉布局把滚动视图按钮下面,像这样:

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

完美的答案!像魅力一样工作。 Manveer Chawla的评论也适用 –