android:cardView宽度与它的父级不匹配

时间:2016-08-02 11:44:22

标签: android android-layout android-recyclerview android-cardview

请仔细阅读 - 我不知道这里出了什么问题。 CardView Bottom中的每一个都与它的父级不匹配。!

我尝试向RecyclerView添加背景,并为CardView提供透明背景

custom_row代码 -

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.CardView
    android:id="@+id/cardView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:foreground="?android:attr/selectableItemBackground"
    card_view:cardCornerRadius="@dimen/card_album_radius">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:paddingBottom="7.5dp"
        android:paddingTop="7.5dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:orientation="horizontal">

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp">

                <com.makeramen.roundedimageview.RoundedImageView
                    android:id="@+id/imageView1"
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:layout_centerInParent="true"
                    android:src="@drawable/ic_action_movie" />

            </RelativeLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="8dp"
                android:layout_marginTop="8dp"
                android:layout_weight="0.75"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/playList_name"
                    android:layout_width="240dp"
                    android:layout_height="match_parent"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="16dp"
                    android:ellipsize="end"
                    android:maxLines="1"
                    android:text="SongName"
                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Title"
                    android:textColor="#c1c1c1"
                    android:textSize="16sp" />

                <TextView
                    android:id="@+id/album_artist"
                    android:layout_width="240dp"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/playList_name"
                    android:layout_marginLeft="16dp"
                    android:layout_weight="0.25"
                    android:ellipsize="end"
                    android:maxLines="1"
                    android:text="ARTIST"
                    android:textColor="#a1a1a1"
                    android:textIsSelectable="false"
                    android:textSize="12sp" />


            </LinearLayout>

            <ImageView
                android:id="@+id/my_overflow"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_weight="1.4"
                android:paddingRight="16dp"
                android:scaleType="fitEnd"
                android:src="@drawable/ic_grade" />

        </LinearLayout>

    </RelativeLayout>

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

这里有 song_fragment.xml -

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ansh.albums.Fragments.Songs">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>

这是我得到的结果 - image

我不知道为什么每个cardView都与它底部的父宽度不匹配?

请帮忙。

1 个答案:

答案 0 :(得分:0)

你可以尝试使用这个来获得底部分隔线

<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:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/cv"
    card_view:cardElevation="0dp"
    card_view:cardMaxElevation="0dp"
    card_view:cardPreventCornerOverlap="false">
相关问题