2012-03-20 96 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

相關問題