0

所以我正在尝试创建一个具有 ListView 的屏幕,并且我需要能够在屏幕底部边缘浮动另一个自定义水平 ListView。当用户在垂直列表视图上滚动时,水平列表视图将不可见并在滚动停止时重新出现。我认为 FrameLayout 将是重叠视图的最佳选择。但我似乎无法完成这项工作。水平列表视图似乎占据了整个屏幕空间。有任何想法吗?这甚至是正确的方法吗?我希望在 HTML 中有类似于固定 div 的东西。
这是我的 XML:

UPDATE-1:按照建议使用 RelativeLayout,但仍然不行。Horizo​​ntalListView 似乎仍然占据了整个屏幕。我从这里使用 HorizintalListView

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ListView
        android:id="@+id/messages" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:layout_marginTop="5dip" />


    <RelativeLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <test.ui.app.HorizontalListView 
                android:id="@+id/folders"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:background="#FFFFFF" />

    </RelativeLayout>



</RelativeLayout>
4

3 回答 3

2

我通过自己设置内部相对布局的高度而不是使用“wrap_content”来让它工作。

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ListView
        android:id="@+id/messages" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" />


    <RelativeLayout 
        android:layout_width="wrap_content" 
        android:layout_height="80dip"
        android:layout_alignParentBottom="true" >

        <test.ui.app.HorizontalListView 
                android:id="@+id/folders"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:background="#FFFFFF" />

    </RelativeLayout>



</RelativeLayout>
于 2011-10-24T09:15:42.417 回答
0

您无法在FrameLayout内调整视图。因此,您最好选择RelativeLayout。或者您可以将列表视图放在 RelativeLayout 或 linearlayout 中,然后进行调整。

希望这会帮助你。:)

于 2011-10-20T12:43:30.710 回答
0

就像其他回答者所说,您可以使用RelativeLayout:

  • 为垂直列表视图设置 android:layout_alignParentLeft|Right|Top|Bottom="true"
  • 将 android:layout_alignParentLeft|Right|Bottom="true" 设置为水平列表视图(并将高度设置为“wrap_content”或固定大小)

或者,如果您想坚持使用 FrameLayout(可能出于性能原因......),您可以简单地将一个巨大的 android:layout_marginTop 添加到水平列表视图中。但是这个解决方案更丑陋,因为您需要设置精确的值。例如,如果整个屏幕的高度为 320dp,而您希望水平列表视图的高度为 80dp,则需要将上边距设置为 240dp。但是,如果您在具有不同纵横比的屏幕上运行它,水平列表视图将很难看。

于 2011-10-20T14:40:56.520 回答