我目前正在使用 GridLayout 来获得一个看起来像这样的视图:
我正在尝试通过定义以下布局 xml 来创建此布局:
<android.support.v7.widget.GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="5"
android:rowCount="2" >
<LinearLayout
android:id="@+id/banner"
android:layout_row="0"
android:layout_columnSpan="5"
android:orientation="horizontal" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_row="1"
android:layout_columnSpan="2" />
<RelativeLayout android:id="@+id/previewpane"
android:layout_row="1"
android:layout_column="2"
android:layout_columnSpan="3"/>
</android.support.v7.widget.GridLayout>
虽然编译和运行不会崩溃,但 ViewPager 出于某种原因占用了所有屏幕空间。为什么会发生这种情况(看到它应该只占据 5 列中的 2 列,并且只占底行)以及如何更改此布局以正确显示,如图所示?