Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android全宽CardView_Android - Fatal编程技术网

Android全宽CardView

Android全宽CardView,android,Android,这是我得到的输出:-(我没有足够的积分来发布图片) 以下是我正在使用的XML代码:- <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cardview="http://schemas.android.com/apk/res-auto"

这是我得到的输出:-(我没有足够的积分来发布图片)

以下是我正在使用的XML代码:-

   <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
                                    xmlns:cardview="http://schemas.android.com/apk/res-auto"
                                    xmlns:tools="http://schemas.android.com/tools"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:id="@+id/myCardView"
                                    cardview:cardUseCompatPadding="true"
                                    cardview:cardCornerRadius="2dp"
                                    cardview:cardElevation="4dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:id="@+id/relLayout"
        android:layout_margin="10dp"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/thumbnail"
            android:layout_width="100dp"
            android:layout_height="80dp"
            android:scaleType="centerCrop"
            android:src="@drawable/placeholder"
            android:contentDescription="Event Image"
            android:layout_weight="1"
            />
        <LinearLayout
            android:layout_weight="20"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:id="@+id/title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:maxLines="3"
                android:padding="8dp"
                android:text="Event Title"
                android:textColor="#222"
                android:textSize="20sp"
                android:layout_gravity="top|left"
                android:gravity="top"
                tools:ignore="RtlHardcoded"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Short Description of Event"
                android:textColor="#222"
                tools:ignore="RtlHardcoded"
                android:maxLines="3"
                android:id="@+id/short_desc"
                android:padding="8dp"/>
            <View
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1000"/>
        </LinearLayout>
    </LinearLayout>
</android.support.v7.widget.CardView>

我想得到一个全宽度的卡片视图,这是我无法实现的。 救命啊!谢谢:)

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:cardUseCompatPadding="true"
    card_view:cardCornerRadius="2dp"
    card_view:cardElevation="4dp">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

           ....

    </LinearLayout>

</android.support.v7.widget.CardView>

....

您的
onCreateViewHolder中有什么
试试这样给你的卡充气

final View itemView = LayoutInflater.
            from(parent.getContext()).
            inflate(R.layout.item_preview, parent, false);

是否确实已将“宽度”设置为“匹配父项”
?和显示根布局。您想要Java实现吗?您可以向您显示recycler xml或activity xml,在其中设置卡视图。可能有填充物。。well cardview:cardUseCompatPadding确实在API v21+中添加了填充,以便与以前的版本具有相同的测量值。