底部水平均分导航栏布局

发表于 2020-05-19
阅读 21

介绍

介绍

说到 app 程序一定会有的就是顶部导航栏和底部导航栏

今天我们来学习底部导航栏的布局设计

教程

要点

  • 利用线性布局的 layout_weight 属性实现水平均分按钮

  • 使用 ImageView 和 TextView 组合实现上面图标下面文字的布局

实例

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

    <LinearLayout
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#eeeeee">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1">
            <ImageView
                android:id="@+id/mm_btn_home"
                android:layout_width="match_parent"
                android:layout_height="25dp"
                android:layout_marginTop="5dp"
                android:src="@mipmap/ic_launcher"/>
            <TextView
                android:id="@+id/mm_btntxt_home"
                android:layout_width="match_parent"
                android:layout_height="18dp"
                android:text="首页"
                android:textAlignment="center"
                android:textSize="12sp"/>
        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1">
            <ImageView
                android:id="@+id/mm_btn_me"
                android:layout_width="match_parent"
                android:layout_height="25dp"
                android:layout_marginTop="5dp"
                android:src="@mipmap/ic_launcher"/>
            <TextView
                android:id="@+id/mm_btntxt_me"
                android:layout_width="match_parent"
                android:layout_height="18dp"
                android:text="我"
                android:textAlignment="center"
                android:textSize="12sp"/>
        </LinearLayout>

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

使用

通过 include 方式在 Activity 里引用

鬼谷子叔叔

跟福哥学编程吧~~
日志
212
浏览
1626