我尝试使用以下教程https://guides.codepath.com/android/Using-the-CardView将framelayout更改为CardView。
最初我有代码,
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/note_tile_margin">
<LinearLayout
android:id="@+id/tile_clickable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="@drawable/tile_selector"
android:clickable="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/noteTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="@dimen/tile_padding"
android:layout_toLeftOf="@+id/btn_tile_expand"
android:ellipsize="end"
android:maxLines="@integer/max_tile_lines"
android:singleLine="false"
android:text="Write your message here... "
android:textColor="@color/tile_text" />
<LinearLayout
android:id="@+id/btn_tile_expand"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/click_selector"
android:gravity="top" >
<ImageView
android:id="@+id/btn_tile_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="7dp"
android:src="@drawable/icon_dark_expand" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/tile_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:visibility="gone" >
<ImageView
android:id="@+id/btn_tile_links"
style="@style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="Hyperlinks"
android:src="@drawable/icon_dark_web" />
<ImageView
android:id="@+id/btn_tile_delete"
style="@style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="@string/deleteNote"
android:src="@drawable/icon_dark_delete" />
<ImageView
android:id="@+id/btn_tile_share"
style="@style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="@string/share"
android:src="@drawable/icon_dark_share" />
<ImageView
android:id="@+id/btn_tile_copy"
style="@style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="Copy to clipboard"
android:src="@drawable/icon_dark_copy" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
然后我按照本教程中概述的步骤更改了它告诉我的位。现在,按照步骤和代码似乎很容易,
<?xml version="1.0" encoding="utf-8"?>
<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>
<LinearLayout
android:id="@+id/tile_clickable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="@drawable/tile_selector"
android:clickable="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/noteTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="@dimen/tile_padding"
android:layout_toLeftOf="@+id/btn_tile_expand"
android:ellipsize="end"
android:maxLines="@integer/max_tile_lines"
android:singleLine="false"
android:text="Write your message here... "
android:textColor="@color/tile_text" />
<LinearLayout
android:id="@+id/btn_tile_expand"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/click_selector"
android:gravity="top" >
<ImageView
android:id="@+id/btn_tile_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="7dp"
android:src="@drawable/icon_dark_expand" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/tile_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:visibility="gone" >
<ImageView
android:id="@+id/btn_tile_links"
style="@style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="Hyperlinks"
android:src="@drawable/icon_dark_web" />
<ImageView
android:id="@+id/btn_tile_delete"
style="@style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="@string/deleteNote"
android:src="@drawable/icon_dark_delete" />
<ImageView
android:id="@+id/btn_tile_share"
style="@style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="@string/share"
android:src="@drawable/icon_dark_share" />
<ImageView
android:id="@+id/btn_tile_copy"
style="@style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="Copy to clipboard"
android:src="@drawable/icon_dark_copy" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
然后我去构建项目并收到以下错误消息:
如何正确实施此CardView布局以及出现了什么问题?
注意:这与我的上一个问题Rounding the corners of views in notepad android app相关联。
答案 0 :(得分:1)
你错过了layout_height =“wrap_content”中的引号:
<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">