1

每个项目应覆盖屏幕宽度的 70%。虽然 70% 的屏幕被填满,但我得到了 30% 的空白空间,下一个项目在它之后开始。这是布局 -

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="4"
        app:cardCornerRadius="2dp"
        app:cardElevation="2dp"
        app:cardPreventCornerOverlap="false"
        app:cardUseCompatPadding="true"
        app:contentPadding="2dp"
        app:layout_widthPercent="70%">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/image_test"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"/>

        </FrameLayout>
    </android.support.v7.widget.CardView>
</android.support.percent.PercentRelativeLayout>
4

1 回答 1

0

之前Android Support Library, revision 23.2.1recyclerView没有考虑他itemView的height(vertical)或者width(Horizo​​ntal)。它总是把它包起来。

但现在它考虑高度或宽度。在你的情况下,它是宽度。

所以,让你的 layout_width,match_parentwrap_content

于 2016-03-29T08:58:05.663 回答