【问题标题】:scrollview inside linearlayout forces buttons offscreen线性布局内的滚动视图强制按钮离屏
【发布时间】:2013-01-13 00:02:24
【问题描述】:

我正在尝试构建一个顶部有一个复选框、底部有一个按钮以及在它们之间滚动的一堆其他小部件的活动。概念上是这样
线性布局
复选框
滚动视图
线性布局
[东西]
线性布局端
ScrollView-结束
按钮
线性布局端

当它渲染时,我得到顶部的复选框,下面的东西很好地滚动,但 Button 在 ScrollView 下方绘制在屏幕外(我假设)。我可以让 Button 可见的唯一方法是硬编码 ScrollView 的高度,这当然只适用于一个屏幕尺寸。我已经尝试了所有我能想到的重力和 layout_weight 组合,但都无济于事。我是否使用了正确的视图组合?有人设法让它工作吗?

(我不认为RelativeLayout 是非常合适的容器,但无论如何我希望避免它,因为它在1.5 上被破坏了。)

谢谢,

--埃里克

【问题讨论】:

    标签: android layout


    【解决方案1】:

    我最近遇到了同样的问题,我补充说:

    <ScrollView 
        ...
        android:layout_weight="1" >
    

    这解决了我的问题。

    【讨论】:

      【解决方案2】:

      我在 2.2 中使用过这个,不确定 layout_above 和 layout_below 标签在 1.5 中是否可用(如果那是你使用的)。 布局您想要填充剩余区域的三个主要元素,即页眉、页脚和中心内容(在本例中为列表视图)。

      如果需要,您可以将 Listview 替换为 scrollView 或任何组件。

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent" android:layout_height="fill_parent">
          <Button
              android:id="@+id/header"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="Top Button"/>
          <Button
              android:id="@+id/footer"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentBottom="true"
              android:text="Button"/>
      
          <ListView
              android:id="@android:id/center"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_below="@id/header"
              android:layout_above="@id/footer"/>
          </RelativeLayout>
      

      注意元素的顺序。不确定它是否相关,但中心元素是最后定义的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-04-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多