【问题标题】:Positioning ListViews inside FrameLayout在 FrameLayout 中定位 ListView
【发布时间】:2011-10-20 12:39:01
【问题描述】:

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

UPDATE-1:按照建议使用 RelativeLayout,但仍然不行。 Horizo​​ntalListView 似乎仍然占据了整个屏幕。我正在使用来自here的 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>

【问题讨论】:

    标签: android listview android-framelayout


    【解决方案1】:

    我通过自己设置内部相对布局的高度而不是使用“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>
    

    【讨论】:

      【解决方案2】:

      您无法在 FrameLayout 中调整视图。因此,您最好选择 RelativeLayout。 或者你可以把你的listviews放在RelativeLayout或者linearlayout里面然后你就可以调整了。

      希望这会对您有所帮助。 :)

      【讨论】:

        【解决方案3】:

        就像其他回答者所说,您可以使用相对布局:

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

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

        【讨论】:

        • 我更新了布局以使用 RelativeLayouts,但它似乎也没有帮助。将尝试更多。更新后的布局有什么吸引你的地方吗?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多