添加一条水平线和一些底部带有文本的图标,如 facebook

elm*_*lma -2 android android-layout android-xml android-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>
Run Code Online (Sandbox Code Playgroud)

现在我想在这段代码中添加更多的东西。

我想添加一条水平线。(我想我必须查看)和一些带有文字的图标,如下图:

在此处输入图片说明

我怎样才能做到这一点?

Fer*_*med 5

我为两个不同的CardView. 请参阅附加图像以获取输出。希望能帮到你~

Facebook like CardViewImage,TitleSome 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>
Run Code Online (Sandbox Code Playgroud)

输出:

在此处输入图片说明

Facebook like CardViewImage, Title,Some TextLike, 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>
Run Code Online (Sandbox Code Playgroud)

输出:

在此处输入图片说明