是否可以在CardView中使用ConstraintLayout,以便我可以为RecyclerView充气?
当前的布局是这样的,但我想在CardView中显示它。
https://i.stack.imgur.com/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。