我想要一个左侧的垂直ListView和一个右侧的GridView。两者都由ArrayAdapters支持。我已经尝试了RelativeLayout和LinearLayout,并且GridView甚至没有调用适配器(除非垂直堆叠)。我把一个Log.v放在带有父ID的适配器中来证明它。使用TableLayout,网格的适配器会设置字段,但网格仍不可见。这两个视图确实在其中显示了相同的TextView项目。剩下的片段显示正常。 ListView总是显示。试图在列表视图旁显示一个GridView。 GridView不显示
的XML使用TableLayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_course"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.hubbardsoftware.racetac.CourseActivityFragment"
tools:showIn="@layout/activity_course">
<fragment android:name="com.hubbardsoftware.racetac.TimerFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_timer" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff000000"
android:textStyle="bold"
android:text="@string/course"/>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TableRow>
<ListView
android:id="@+id/listview_course"
android:layout_column="1"
/>
<GridView
android:id="@+id/gridview_course"
android:layout_column="2"
android:numColumns="auto_fit"
android:stretchMode="none" />
</TableRow>
</TableLayout>
和碎片代码:
// Setup the List of Marks in the course.
ArrayList<Mark> course = appData.getCourse();
ArrayList<Mark> marks = appData.getMarks();
Log.v(LOG_TAG, "Adapters: "+course.size()+" "+marks.size());
courseAdapter = new CourseAdapter(getActivity(), R.id.listview_course, R.layout.list_item_mark_name, course);
ListView listView = (ListView) rootView.findViewById(R.id.listview_course);
listView.setAdapter(courseAdapter);
// Setup the grid of Marks to choose from
marksAdapter = new CourseAdapter(getActivity(), R.id.gridview_course, R.layout.list_item_mark_name, marks);
GridView gridView = (GridView) rootView.findViewById(R.id.gridview_course);
gridView.setAdapter(marksAdapter);
这list_item_mark_name的布局:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_item_mark_name_name"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:fontFamily="Roboto"
android:textStyle="bold"
android:textColor="#ff000000"
android:text="name"
/>
我可以让他们垂直堆叠,或者甚至让他们在同一个空间彼此重叠,但没有并肩的欢乐。我已经广泛地使用重量,相对定位(toRightOf等等),并且没有去。
我也只是试图给网格它自己的适配器,并创建另一个网格的不同名称的TextView,无济于事。
想法?谢谢!