android recyclerview中心水平项目

时间:2017-05-08 19:31:50

标签: android android-recyclerview cardview

如何实现这个设计? design 我目前的设计实现如下,如何删除黑色空间? currentImplementation 我目前的回收商视图代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <FrameLayout
            android:id="@+id/gesture_layout"
            android:layout_width="fill_parent"
            android:layout_height="260dp"
            android:background="@color/white"
            android:orientation="horizontal">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_centerHorizontal="true"
                android:background="@color/transparent"
                android:gravity="center_horizontal"
                android:clipToPadding="false"
                android:visibility="visible"
                />

        </FrameLayout>
    </LinearLayout>

我目前的cardView代码

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/black"
    android:layout_gravity="center_horizontal"
    >

    <!-- A CardView that contains a GifImageView -->
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="68dp"
        android:layout_height="68dp"
        card_view:cardCornerRadius="0dp"
        card_view:cardMaxElevation="0dp"
        card_view:cardElevation="0dp"
        card_view:cardBackgroundColor="@color/tab_selected"
        >

        <pl.droidsonroids.gif.GifImageView
            android:id="@+id/emoji"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/transparent"
            />
    </android.support.v7.widget.CardView>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

1。android:layout_width="68dp"android:layout_height="68dp"添加到LinearLayout

2。删除行mRecyclerView.addItemDecoration(new SpacesItemDecoration(10, context));或使用较小的间隙。

3。将属性card_view:cardUseCompatPadding="false"添加到CardView

试试这个:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="68dp"
    android:layout_height="68dp"
    android:background="@color/black"
    android:layout_gravity="center_horizontal">

    <!-- A CardView that contains a GifImageView -->
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        card_view:cardCornerRadius="0dp"
        card_view:cardMaxElevation="0dp"
        card_view:cardElevation="0dp"
        card_view:cardBackgroundColor="@color/tab_selected"
        card_view:cardUseCompatPadding="false">

        <pl.droidsonroids.gif.GifImageView
            android:id="@+id/emoji"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/transparent"/>
    </android.support.v7.widget.CardView>
</LinearLayout>