【问题标题】:Nested Layouts ScrollView嵌套布局滚动视图
【发布时间】:2014-02-20 06:44:44
【问题描述】:

我已经为此苦苦挣扎了一段时间,到目前为止还没有找到答案。 我在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>

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

【问题讨论】:

  • 我认为这可能是因为ScrollView被添加到Button之后的布局中,并且配置为匹配父级的高度和宽度,因此它高于Button 在 z 索引中。尝试在ScrollView 之后添加Button
  • 感谢 Manveer Chawla。我忘记了 ScrollView 在按钮前面。
  • 如果这对您有用,我应该将其发布为答案吗? :)

标签: android android-tablelayout


【解决方案1】:

切勿将可滚动视图放入另一个可滚动视图(滚动方向相同)。这条规则的唯一例外是,当主以他的所有荣耀出现在你面前,并递给你石板时,上面刻有其他内容。

无论如何,第二个布局只需稍加修改即可工作,您必须告诉布局将滚动视图放在按钮下方,如下所示:

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

【讨论】:

  • 完美答案!像魅力一样工作。 Manveer Chawla cmets 也可以工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多