android - 在 CardView 中使用 ConstraintLayout

标签 android android-cardview android-constraintlayout

是否可以在 CardView 中使用 ConstraintLayout 以便为 RecyclerView 膨胀它?

当前的布局是这样的,但我想在 CardView 中显示它。

/image/MeArp.png

引用XML代码:

<android.support.constraint.ConstraintLayout
    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:minHeight="?android:attr/listPreferredItemHeight"
    android:background="@drawable/touch_selector"
    android:paddingBottom="@dimen/list_item_padding_vertical"
    android:paddingLeft="@dimen/list_item_padding_horizontal"
    android:paddingRight="@dimen/list_item_padding_horizontal"
    android:paddingTop="@dimen/list_item_padding_vertical">

    <ImageView
        android:id="@+id/weather_icon"
        android:layout_width="@dimen/list_icon"
        android:layout_height="@dimen/list_icon"
        app:layout_constraintBottom_toTopOf="@+id/guideline"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline"
        tools:src="@drawable/art_clouds"/>

    <TextView
        android:id="@+id/date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/list_item_date_left_margin"
        android:layout_marginStart="@dimen/list_item_date_start_margin"
        android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
        app:layout_constraintBottom_toTopOf="@+id/guideline"
        app:layout_constraintLeft_toRightOf="@+id/weather_icon"
        tools:text="Today, April 03"/>

    <TextView
        android:id="@+id/weather_description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1"
        android:textColor="@color/secondary_text"
        app:layout_constraintLeft_toLeftOf="@+id/date"
        app:layout_constraintTop_toTopOf="@+id/guideline"
        tools:text="Rainy"/>

    <TextView
        android:id="@+id/high_temperature"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="@dimen/forecast_temperature_space"
        android:layout_marginRight="@dimen/forecast_temperature_space"
        android:fontFamily="sans-serif-light"
        android:textColor="@color/primary_text"
        android:textSize="@dimen/forecast_text_size"
        app:layout_constraintBottom_toTopOf="@+id/guideline"
        app:layout_constraintRight_toLeftOf="@+id/low_temperature"
        app:layout_constraintTop_toTopOf="@+id/guideline"
        tools:text="19\u00b0"/>

    <TextView
        android:id="@+id/low_temperature"
        android:layout_width="60dp"
        android:layout_height="wrap_content"
        android:fontFamily="sans-serif-light"
        android:gravity="end"
        android:textSize="@dimen/forecast_text_size"
        app:layout_constraintBottom_toBottomOf="@+id/guideline"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline"
        tools:text="10\u00b0"/>

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.5"/>

</android.support.constraint.ConstraintLayout>

最佳答案

是的,这是可能的!将您的 ConstraintLayout xml 代码放入 CardView 中。您还可以查看各种 card view implementations符合Material design guidelines .

关于android - 在 CardView 中使用 ConstraintLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45280262/

相关文章:

Android:约束布局动画选项卡选择

java - Cardview 是全部进入一张卡片

android - ConstraintLayout 中的边距如何工作?

java - fragment 必须是公共(public)静态类才能从实例状态正确地重新创建

android - 错误 : This version of the application is not configured for billing through Google Play

android - 在 Android 的锁定屏幕上显示自定义信息

android - Intent.ACTION_VIEW 在可搜索中不起作用

android - 想在 android 中的 CardView 的卡片之间添加水平间距?

android - 如何从主题更改 CardView 背景颜色

android - 约束布局中的可滚动 TextView