我正在尝试使用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);
我得到一种感觉,它有事可做与我如何膨胀的布局。任何帮助,将不胜感激。谢谢。
更改layout_height没有解决它。我把标题放在ListView之外,它工作得很好。它只在ListView中做到这一点。在来到这里之前,我尝试了层次结构视图,但我无法确定发生了什么。元素是正确的宽度,尽我所知。纺纱工作正常。 – Jess
如果我不向ListAdapter添加任何其他视图,它工作正常。 – Jess
@Andrew Koester:如果你创建了一个完整的示例项目来演示这个问题,我可以看看它。 – CommonsWare