2017-07-24 70 views
2

是否可以在CardView中使用ConstraintLayout以便我可以爲RecyclerView充氣?在CardView中使用ConstraintLayout

當前佈局是這樣的,但我想在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> 
+0

您是否嘗試將此ConstraintLayout放入CardView中? – Pei

回答

相關問題