ConstraintLayout实现九宫格样式

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u012854870/article/details/89636740

转载请注明:https://blog.csdn.net/u012854870/article/details/89636740

ConstraintLayout实现九宫格样式:

<?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:background="@color/white">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:minHeight="?attr/actionBarSize"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/epanel" />
    </android.support.v7.widget.Toolbar>

    <ImageView
        android:id="@+id/iv_live"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/dp_10"
        android:adjustViewBounds="true"
        android:src="@mipmap/zhibo_banner"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar" />

    <TextView
        android:id="@+id/text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/dp_17"
        android:layout_marginTop="@dimen/dp_30"
        android:layout_marginEnd="@dimen/dp_17"
        android:text="@string/str_initiate_approval"
        android:textColor="@color/color_333333"
        android:textSize="@dimen/sp_16"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/iv_live" />

    <!---->


    <TextView
        android:id="@+id/tv_ask_for_leave"
        style="@style/officeTextView"
        android:drawableTop="@mipmap/icon_ask_for_leave"
        android:text="@string/str_ask_for_leave"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@id/tv_overtime"
        app:layout_constraintTop_toBottomOf="@id/text_view" />

    <TextView
        android:id="@+id/tv_overtime"
        style="@style/officeTextView"
        android:drawableTop="@mipmap/icon_overtime"
        android:text="@string/str_overtime"
        app:layout_constraintLeft_toRightOf="@id/tv_ask_for_leave"
        app:layout_constraintRight_toLeftOf="@id/tv_business_trip"
        app:layout_constraintTop_toBottomOf="@id/text_view" />

    <TextView
        android:id="@+id/tv_business_trip"
        style="@style/officeTextView"
        android:drawableTop="@mipmap/icon_business_trip"
        android:text="@string/str_business_trip"
        app:layout_constraintLeft_toRightOf="@id/tv_overtime"
        app:layout_constraintRight_toLeftOf="@id/tv_go_out"
        app:layout_constraintTop_toBottomOf="@id/text_view" />

    <TextView
        android:id="@+id/tv_go_out"
        style="@style/officeTextView"
        android:drawableTop="@mipmap/icon_go_out"
        android:text="@string/str_go_out"
        app:layout_constraintLeft_toRightOf="@id/tv_business_trip"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/text_view" />

    <TextView
        android:id="@+id/tv_punch"
        style="@style/officeTextView"
        android:drawableTop="@mipmap/icon_punch"
        android:text="@string/str_punch"
        app:layout_constraintLeft_toLeftOf="@id/tv_ask_for_leave"
        app:layout_constraintRight_toRightOf="@id/tv_ask_for_leave"
        app:layout_constraintTop_toBottomOf="@id/tv_ask_for_leave" />

    <TextView
        android:id="@+id/tv_payment"
        style="@style/officeTextView"
        android:drawableTop="@mipmap/icon_payment"
        android:text="@string/str_payment"
        app:layout_constraintLeft_toLeftOf="@id/tv_overtime"
        app:layout_constraintRight_toRightOf="@id/tv_overtime"
        app:layout_constraintTop_toBottomOf="@id/tv_overtime" />
</android.support.constraint.ConstraintLayout>

Styles:

 <style name="officeTextView">
        <item name="android:layout_width">@dimen/dp_0</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:gravity">center</item>
        <item name="android:textColor">@color/color_333333</item>
        <item name="android:textSize">@dimen/sp_13</item>
        <item name="android:drawablePadding">@dimen/dp_14</item>
        <item name="android:layout_marginTop">@dimen/dp_20</item>
        <item name="layout_constrainedWidth">true</item>
        <item name="layout_constraintDimensionRatio">1:1</item>
        <item name="layout_constraintHorizontal_weight">1</item>
        <item name="android:clickable">true</item>
        <item name="android:focusable">true</item>
        <item name="android:foreground">?attr/selectableItemBackground</item>
    </style>

 

展开阅读全文

没有更多推荐了,返回首页