水平RecyclerView没有包裹布局

时间:2016-03-29 08:29:43

标签: android android-recyclerview linearlayoutmanager

每个项目应覆盖屏幕宽度的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>

1 个答案:

答案 0 :(得分:0)

#include <unistd.h> // For "access()" function #include <errno.h> // For "errno" #include <string.h> // For "strerror()" function // add your stuffs here ... // ..... // ..... int status = access(filename, F_OK); int saved_error = errno; // For errno include <errno.h> if (status == -1) { fprintf(stderr, "File Error: %s\n", strerror(saved_error)); // For "strerror" include <string.h> exit(EXIT_FAILURE); } // Now here file will exist and can be opened as: FILE *fptr = fopen(filename, "r"); saved_error = errno; // Read more about errno: "man errno" commend in linux // check for error if(fptr == NULL){ fprintf(stderr, "File error: %s\n", strerror(saved_error); exit(EXIT_FAILURE); } // Now access you file using fptr... recyclerView之前没有考虑他的itemView的高度(垂直)或宽度(水平)。它总是把它包起来。

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

因此,请将Android Support Library, revision 23.2.1layout_width设为match_parent