2

我正在嘗試使用Fragments在Android中進行佈局。我開始使用Commonsware的MergeAdapter,但我有點奇怪。佈局工作過罰款,但現在我得到這樣的:在片段中的MergeAdapter佈局問題

http://img856.imageshack.us/img856/2796/layoutbug.png

有幾個問題:白條應該有文本會在其長度的所有道路。我將TextView設置爲白色背景,以確保寬度設置正確。它下面的複選框也應該說「問題?」但由於某種原因它試圖包裝文本。

這裏是正在添加的佈局代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> 
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Instructions" /> 
    <TextView android:id="@+id/tvInstructions" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Instructions go here" android:textSize="32dp" android:background="#FFFFFF"></TextView> 
    <LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="horizontal" android:paddingTop="24dp"> 
     <CheckBox android:id="@+id/cbIssues" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="0dp" android:text="Issues?" /> 
     <TextView android:id="@+id/tvStation" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight=".5" android:text="Station:" /> 
     <Spinner android:id="@+id/spStation" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight=".5"/> 
    </LinearLayout> 
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Pending data" /> 
</LinearLayout> 

,這裏是我是如何誇大它的碎片的onActivityCreated內:

LayoutInflater inflater = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
MergeAdapter _adapter = new MergeAdapter(); 

View observationHeaderView = inflater.inflate(R.layout.observationheader, getListView(), false); 
_adapter.addView(observationHeaderView); 

我得到一種感覺,它有事可做與我如何膨脹的佈局。任何幫助,將不勝感激。謝謝。

回答

0

看來我的問題是layout_widthmatch_parent在我的標題的某些地方,應該是wrap_content。以下工作:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> 
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Instructions" /> 
    <TextView android:id="@+id/tvInstructions" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Instructions go here" android:textSize="32dp" android:background="#FFFFFF"></TextView> 
    <LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="horizontal" android:paddingTop="24dp"> 
     <CheckBox android:id="@+id/cbIssues" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content" android:text="Issues?" /> 
     <TextView android:id="@+id/tvStation" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight=".5" android:text="Station:" /> 
     <Spinner android:id="@+id/spStation" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight=".5"/> 
    </LinearLayout> 
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Pending data" /> 
</LinearLayout> 
1

請勿使用match_parent替換android:layout_height以查看AdapterView,如您的根LinearLayout

你也可以考慮暫時把你的頭佈局ListView外(例如,在垂直LinearLayout還拿着ListView),並把它添加在ListView有它的併發症之前調試。

除此之外,啓動層次結構視圖(Eclipse透視圖或獨立版)並嘗試找出佈局規則出錯的位置。

此外,我不確定您的Spinners將在蜂窩上的ListView內工作得如何。

+0

更改layout_height沒有解決它。我把標題放在ListView之外,它工作得很好。它只在ListView中做到這一點。在來到這裏之前,我嘗試了層次結構視圖,但我無法確定發生了什麼。元素是正確的寬度,盡我所知。紡紗工作正常。 – Jess

+0

如果我不向ListAdapter添加任何其他視圖,它工作正常。 – Jess

+0

@Andrew Koester:如果你創建了一個完整的示例項目來演示這個問題,我可以看看它。 – CommonsWare