1
카드보기는 성냥 부모 대신 내용을 래핑합니다. 모든 목록 항목은 너비와 일치하는 대신 줄 바꿈됩니다. CardView는 match_parent 대신 wrap_content 목록 항목입니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="@dimen/card_margin"
android:elevation="3dp"
card_view:cardCornerRadius="@dimen/card_album_radius">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/Album_Art"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="@drawable/ic_google_music" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/song_name"
android:id="@+id/Sname"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/Album_Art"
android:layout_toEndOf="@+id/Album_Art" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/artist_album"
android:id="@+id/Sdata"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_toRightOf="@+id/Album_Art"
android:layout_toEndOf="@+id/Album_Art"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
수동으로 폭 작동을 설정. 큰 dp 값으로 설정하면 목록 항목이 창 밖으로 나오는 것을 제외하고는 잘 작동합니다. match_parent가 작동하지 않는 이유를 모르겠습니다. 이 문제를 해결하는 방법에 대한 모든 리드가 크게 감사하겠습니다.
당신이 당신의'Adapter'의 레이아웃을 부풀려 때 부모에 null을 전달하는 추측 것입니다. –
@MikeM. 네, 제가 무엇을 통과해야합니까? –
'ViewGroup'은 레이아웃을 부 풀리는 메소드에 전달됩니다. 아마도'parent'라고 명명되었을 것입니다. –