ConstraintLayout + CardView + Space + Guideline 使用

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:layout_margin="16dp"
        app:cardCornerRadius="12dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/zard1"
            android:scaleType="centerCrop" />
    </android.support.v7.widget.CardView>

    <Space
        android:id="@+id/space"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="80dp"
        app:layout_constraintBottom_toBottomOf="@id/cardView"
        app:layout_constraintLeft_toLeftOf="@id/cardView"
        app:layout_constraintRight_toRightOf="@id/cardView" />

    <android.support.v7.widget.CardView
        android:layout_width="160dp"
        android:layout_height="160dp"
        app:cardCornerRadius="8dp"
        app:layout_constraintEnd_toEndOf="@id/cardView"
        app:layout_constraintStart_toStartOf="@id/cardView"
        app:layout_constraintTop_toBottomOf="@id/space">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/zard"
            android:scaleType="centerCrop" />

    </android.support.v7.widget.CardView>


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

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


    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_green_dark"
        android:gravity="center"
        android:padding="8dp"
        android:text="Zard"
        android:textSize="18sp"
        app:layout_constraintLeft_toRightOf="@id/guideline_w"
        app:layout_constraintTop_toBottomOf="@id/guideline_h" />

    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_orange_dark"
        android:gravity="center"
        android:padding="8dp"
        android:text="坂井泉水"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="@id/guideline_h"
        app:layout_constraintRight_toRightOf="@id/guideline_w" />

    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_red_dark"
        android:gravity="center"
        android:padding="8dp"
        android:text="Japan"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="@id/guideline_h"
        app:layout_constraintLeft_toRightOf="@id/guideline_w" />

    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_blue_bright"
        android:gravity="center"
        android:padding="8dp"
        android:text="姐姐"
        android:textSize="18sp"
        app:layout_constraintRight_toRightOf="@id/guideline_w"
        app:layout_constraintTop_toBottomOf="@id/guideline_h" />


</android.support.constraint.ConstraintLayout>

​

注意:使用CardView 進行佈局疊加覆蓋時,如果最外層的疊加部分的佈局不顯示,將CardView設置android:elevation="0dp".

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章