我正在尝试实现这种布局
<RelativeLayout>
<LinearLayout> <!-- Always attached to the top of the parent -->
<RecyclerView>
<LinearLayout> <!-- Always attached to the bottom of the parent -->
<GridView>
<RelativeLayout>
这是完整的代码,在相对布局内的两个线性布局之间具有回收器 View
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<LinearLayout
android:id="@+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="160dp"/>
<LinearLayout
android:id="@+id/layoutDots"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignBottom="@id/view_pager"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="horizontal" />
<View android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_below="@id/view_pager"
android:background="@android:color/darker_gray" />
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_below="@id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View android:layout_width="0dp"
android:layout_height="1dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:layout_margin="10dp"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/orLoginWithEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical"
android:text="Shop By Category"
android:textColor="@color/black"
android:textSize="16sp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_margin="10dp"
android:background="@android:color/darker_gray" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/LinearLayout1"
android:layout_below="@id/LinearLayout"
android:background="@android:color/white"
android:orientation="horizontal"/>
<GridView
android:id="@+id/gridview"
android:layout_below="@id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:horizontalSpacing="10dp"
android:numColumns="4"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:paddingTop="10dp"
android:verticalSpacing="20dp"></GridView>
</RelativeLayout>
我试图将回收器 View 放置在父相对布局内的两个线性布局之间,但它没有显示回收器 View 。我认为它与某些 View 重叠或可能存在任何其他问题。我当前的布局输出是
最佳答案
添加此代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<LinearLayout
android:id="@+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="160dp" />
<LinearLayout
android:id="@+id/layoutDots"
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center"
android:orientation="horizontal" />
<View
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@android:color/darker_gray" />
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/listView">
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_gravity="center_vertical"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/orLoginWithEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical"
android:text="Shop By Category"
android:textColor="#000000"
android:textSize="16sp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_gravity="center_vertical"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="@android:color/darker_gray" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/LinearLayout"
android:background="@android:color/white"
android:orientation="horizontal" />
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/LinearLayout1"
android:horizontalSpacing="10dp"
android:numColumns="4"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:paddingTop="10dp"
android:verticalSpacing="20dp" />
关于android - 在 2 个 View 之间放置一个 recyclerview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46378176/