我想在cardview中添加一个页脚。
我在RecyclerView中的当前XML布局是这样的:
(此xml代码充当RecyclerView中的行)
码
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="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:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="@dimen/activity_margin_half"
app:cardBackgroundColor="@color/placeholder_grey"
app:cardCornerRadius="6dp"
app:cardPreventCornerOverlap="false">
<ProgressBar
android:id="@+id/movie_progress"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="@dimen/activity_margin"
android:layout_height="@dimen/activity_margin"
android:layout_gravity="center"
android:theme="@style/CircularProgress"/>
<ImageView
android:id="@+id/movie_poster"
android:layout_width="@dimen/poster_thumb_width"
android:layout_height="@dimen/poster_thumb_height"/>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_marginTop="@dimen/activity_margin"
android:background="@drawable/bg_round_rect"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin"
android:paddingLeft="@dimen/poster_thumb_width"
android:paddingRight="@dimen/activity_margin"
android:paddingStart="@dimen/poster_thumb_width"
android:paddingTop="@dimen/activity_margin_half">
<TextView
android:id="@+id/movie_year"
style="@style/TextAppearance.AppCompat.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_margin_content"
android:layout_marginStart="@dimen/activity_margin_content"
android:alpha="0.38"
android:gravity="start"
android:maxLines="1"
android:textStyle="bold"
android:textColor="#f14e4e"
tools:text="2009 | EN"/>
<TextView
android:id="@+id/movie_title"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_margin_content"
android:layout_marginStart="@dimen/activity_margin_content"
android:layout_marginTop="@dimen/activity_margin_quarter"
android:textColor="#9b92b3"
android:maxLines="1"
tools:text="Movie Title"/>
<TextView
android:id="@+id/movie_desc"
style="@style/TextAppearance.AppCompat.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_margin_content"
android:layout_marginStart="@dimen/activity_margin_content"
android:layout_marginTop="@dimen/activity_margin_half"
android:ellipsize="end"
android:maxLines="2"
android:textColor="#9b92b3"
tools:text="Nowadays, user engagement is considered one of the most important metrics for the success of your app"/>
</LinearLayout>
</FrameLayout>
现在我想为此代码添加更多内容。
我想添加一条水平线。 (我想我必须查看)和一些带有文字的图标如下图所示:
我该怎么做?
答案 0 :(得分:2)
我为两个不同的CardView
设计了两个XML。有关输出,请参见附图。希望这会对你有帮助〜
Facebook like CardView
与Image
,Title
和Some Text
:
<?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"
android:id="@+id/card"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="2dp"
card_view:cardUseCompatPadding="false" >
<!-- Content -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="88dp">
<!-- Thumbnail :: Image-->
<ImageView
android:id="@+id/image_thumbnail"
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher"/>
<!-- Two-Line TextView -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image_thumbnail"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<TextView
android:id="@+id/text_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="16dp"
android:layout_marginRight="8dp"
android:maxLines="2"
android:ellipsize="end"
android:fontFamily="sans-serif"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#000000"
android:text="This is a title"/>
<TextView
android:id="@+id/text_subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/text_title"
android:layout_marginTop="4dp"
android:maxLines="2"
android:ellipsize="end"
android:fontFamily="sans-serif"
android:textSize="14sp"
android:textColor="#000000"
android:text="Here is Some text" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<强>输出:强>
Facebook like CardView
Image
,Title
,Some Text
和Like
,Comment
,Share
行为:< /强>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/card"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="2dp"
card_view:cardUseCompatPadding="false" >
<!-- Content -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="88dp">
<!-- Thumbnail :: Image-->
<ImageView
android:id="@+id/image_thumbnail"
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher"/>
<!-- Two-Line TextView -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image_thumbnail"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<TextView
android:id="@+id/text_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="16dp"
android:layout_marginRight="8dp"
android:maxLines="2"
android:ellipsize="end"
android:fontFamily="sans-serif"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#000000"
android:text="This is a title"/>
<TextView
android:id="@+id/text_subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/text_title"
android:layout_marginTop="4dp"
android:maxLines="2"
android:ellipsize="end"
android:fontFamily="sans-serif"
android:textSize="14sp"
android:textColor="#727272"
android:text="Here is Some text" />
</RelativeLayout>
<!-- Bottom line with actions -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@id/image_thumbnail">
<!-- Horizontal line -->
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#ababab">
</View>
<!-- Like + Comment + Share -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:weightSum="4">
<!-- Like -->
<LinearLayout
android:id="@+id/layout_like"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.2"
android:orientation="horizontal"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:gravity="center_vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_like"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:maxLines="1"
android:ellipsize="end"
android:fontFamily="sans-serif"
android:textSize="16sp"
android:textColor="#727272"
android:text="Like"
android:textStyle="bold"/>
</LinearLayout>
<!-- Comment -->
<LinearLayout
android:id="@+id/layout_comment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.6"
android:orientation="horizontal"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:gravity="center_vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_comment"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="4dp"
android:maxLines="1"
android:ellipsize="end"
android:fontFamily="sans-serif"
android:textSize="16sp"
android:textColor="#727272"
android:text="Comment"
android:textStyle="bold"/>
</LinearLayout>
<!-- Share -->
<LinearLayout
android:id="@+id/layout_share"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.2"
android:orientation="horizontal"
android:paddingLeft="8dp"
android:paddingRight="16dp"
android:gravity="center_vertical|right">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_share"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="4dp"
android:maxLines="1"
android:ellipsize="end"
android:fontFamily="sans-serif"
android:textSize="16sp"
android:textColor="#727272"
android:text="Share"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<强>输出:强>
答案 1 :(得分:0)
在cardView
下添加如下视图<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/black"/>
然后使用它下面的LinearLayout / RelativeLayout来保存图标和文字
答案 2 :(得分:0)
请尝试这个....希望可以帮助
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<FrameLayout
android:layout_width="80dp"
android:layout_height="80dp">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:src="@drawable/ic_launcher"
android:layout_height="match_parent" />
</FrameLayout>
<android.support.v4.widget.Space
android:layout_width="24dp"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Title"/>
<Space
android:layout_width="match_parent"
android:layout_height="8dp" />
<TextView
android:id="@+id/some_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="some text"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<FrameLayout
android:layout_width="0dp"
android:layout_weight="1"
android:padding="4dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:drawableLeft="@drawable/ic_launcher"
android:text="Like"
/>
</FrameLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@android:color/black"/>
<FrameLayout
android:layout_width="0dp"
android:layout_weight="1"
android:padding="4dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:drawableLeft="@drawable/ic_launcher"
android:text="Like"
/>
</FrameLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@android:color/black"/>
<FrameLayout
android:layout_width="0dp"
android:layout_weight="1"
android:padding="4dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:drawableLeft="@drawable/ic_launcher"
android:text="Like"
/>
</FrameLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>