2012-03-20 43 views
1

我正在试图制作一个文件管理器应用程序,其中我列出了屏幕上半部分ListFragment中某个目录的内容(不用说这个列表可以滚动),当用户点击某个文件/文件夹时,与它关联的元数据应该在放在片段正下方的FrameLayout中可见,以及文件类型的缩略图。这是我的布局:如何使一个ListFragment仅占用屏幕的上半部分

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#00000000"> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.4" > 

<fragment 
    android:id="@+id/titles" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    class="com.test.fileManager.FileManagerActivity$TitlesFragment" 
/> 

</ScrollView> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.6" 
    android:background="#00000000" 
    > 
</FrameLayout> 

</LinearLayout> 

我用“layout_weight”属性首先没有了滚动标签,但那些重性只是没有被碎片尊重和列表远远高达屏幕的底部。

当我把ScrollView标签中的片段(我知道..不是一个好主意!),我一次只能看到列表中的一个条目。

无论如何,我可以让ListFragment占据屏幕的前40%,并在必要时在40%的屏幕空间中显示可滚动列表?

回答

5

首先,摆脱ScrollView。如果TitlesFragmentListFragment,则无法可靠地将ListView(来自ListFragment)置于ScrollView中。

接下来,将片段的高度设置为0px。您无法可靠地使用match_content作为ListView的高度。

然后,纯粹按百分比做的事情,还设置你的FrameLayout的高度0px,那么,你想你的分配权重(例如,40的片段和60中FrameLayout)。

+0

这就像一个魅力!我知道在ScrollView中嵌入一个可滚动的实体是一个坏主意。我没有太在意高度参数,因为我认为无论如何,当他们指定重量属性时(垂直方向),它们被UI框架忽略了,但这绝对不是这种情况。非常感谢! – HungryTux 2012-03-20 12:30:54

+0

@HungryTux:如果它帮助你,你可能会想要答案:) – Namratha 2013-01-24 09:09:12

相关问题