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