在 FrameLayout 中定位 ListView
因此,我尝试创建一个具有 ListView 的屏幕,并在其上方我需要能够在屏幕的底部边缘浮动另一个自定义水平 ListView。当用户在垂直列表视图上滚动时,水平列表视图将消失并在滚动停止时重新出现。我认为 FrameLayout 是重叠视图的最佳选择。但我似乎无法完成这项工作。水平列表视图似乎占据了整个屏幕空间。有什么想法吗?这是正确的方法吗?我希望在 HTML 中有类似于固定 div 的东西。
这是我的 XML:
UPDATE-1:按照建议使用relativelayout,但仍然不行。 HorizontalListView 似乎仍然占据整个屏幕。我正在使用 此处 中的 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>
So I'm trying to create a screen which has a ListView and over that I need to be able to float another custom horizontal ListView, right at the bottom edge of the screen. When the user scrolls on the vertical listview, the horizontal one would go invisible and reappear when the scrolling stops. I figured FrameLayout would be my best bet for overlapping views. But I can't seem to make this work. The Horizontal listview seems to occupy the whole screen space. Any ideas? Is this even the right approach? I wish to have something similar to a fixed div in HTML.
Here's my XML:
UPDATE-1: Used RelativeLayout as suggested, but still a no-go. The HorizontalListView still seems to be occupying the whole screen. I'm using the HorizintalListView from here
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我通过自己设置内部相对布局的高度而不是使用“wrap_content”来使其工作。
I got it to work by setting the height of the inner Relative Layout myself instead of using 'wrap_content'.
您无法在FrameLayout中调整视图。因此,您最好选择RelativeLayout。
或者您可以将列表视图放入RelativeLayout或线性布局中,然后您可以进行调整。
希望这会对您有所帮助。 :)
You cannot adjust the views inaide FrameLayout.So it will be better for you to go for RelativeLayout.
Or you can put your listviews inside RelativeLayout or linearlayout and then you can adjust.
Hope this will help you. :)
就像其他回答者所说,您可以使用相对布局:
或者如果你真的想坚持使用 FrameLayout (也许是出于性能原因......),你可以简单地添加一个巨大的android:layout_marginTop 到水平列表视图。但这个解决方案比较丑陋,因为您需要设置精确的值。例如,如果整个屏幕的高度为 320dp,而您希望水平列表视图的高度为 80dp,则需要将上边距设置为 240dp。但是,如果您在不同宽高比的屏幕上运行它,水平列表视图将会很难看。
Like the other answerer said, you could use a RelativeLayout:
Or if you reeeeaaaally want to stick with FrameLayout (maybe for performance reasons...), you could somply add a huge android:layout_marginTop to the horizontal list view. But this solution is uglier, since you need to set exact values. For example if the whole screen is 320dp height, and you want the horizontal list view to be 80dp height, you need to set the top margin to 240dp. However if you run this on a screen with different aspect ratio, the horizontal list view will be ugly.