简单实现多布局底部固定显示+中部滑动 仿Tab底部

如何布局底部固定显示!接下来直接上布局代码 重要的有3点 仔细看完 谢谢

在这里插入图片描述

这个效果类似底部TAB 但不需要那么复杂 接下来看代码

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    android:layout_weight="1"  //   这个属性是必须的  不然 底部布局会溢出
    android:layout_width="match_parent"
    android:layout_height="match_parent">
//ScrollView必须嵌套线性布局
    <LinearLayout    
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
        android:id="@+id/home_item_img"
        android:layout_width="match_parent"
        android:layout_height="300dp" />

        <TextView
            android:id="@+id/home_item_sale_price"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="28dp"
            android:text="@string/cash_item_money"
            android:textColor="@color/appBackGround"
            android:textSize="18dp" />

        <TextView
            android:id="@+id/home_item_price"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="2dp"
            android:text="@string/cash_item_money"
            android:textColor="@color/appBackGround"
            android:textSize="14dp" />

        <TextView
            android:id="@+id/home_item_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="2dp"
            android:text="@string/cash_item_money"
            android:textColor="@color/appBackGround"
            android:textSize="18dp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="18dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:text="@string/home_yixuan" />

            <TextView
                android:id="@+id/home_size"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="aaa" />

        </LinearLayout>
        <!--分割线-->
        <View
            android:layout_width="wrap_content"
            android:layout_height="1dp"
            android:layout_marginTop="2dp"
            android:background="#e6e6e6" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="8dp"
                android:text="@string/home_songzhi" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="5dp"
                android:background="@drawable/go_to" />

            <TextView
                android:id="@+id/home_go_to"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="5dp"
                android:layout_weight="1"
                android:text="aaa" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:background="@drawable/right" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_weight="1"
                android:text="@string/home_pingjia"
                android:textColor="@color/appBackGround" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:text="@string/home_chakan"
                android:textColor="@color/appBackGround" />
        </LinearLayout>
        <!--分割线-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <!--分割线-->
            <View
                android:layout_width="60dp"
                android:layout_height="1dp"
                android:layout_marginLeft="8dp"
                android:layout_marginTop="2dp"
                android:background="@color/appBackGround" />
            <!--分割线-->
            <View
                android:layout_width="wrap_content"
                android:layout_height="1dp"
                android:layout_marginTop="2dp"
                android:background="#e6e6e6" />
        </LinearLayout>


    </LinearLayout>
</ScrollView>
//这里是底部布局
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="58dp" //设置高度
    android:orientation="horizontal" //水平布局
    android:gravity="bottom">  //这条属性也是必须要的  
    <LinearLayout
        android:id="@+id/bottom_hi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="22dp"
        android:orientation="vertical">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/kefu"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/kefu"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="28dp"
        android:orientation="vertical">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/shop_select"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/shop_title"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="38dp"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="32dp"
        android:background="@drawable/bt_shape"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="5dp"
            android:textColor="@color/light"
            android:text="@string/add_shop"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:paddingRight="5dp"
            android:textColor="@color/light"
            android:layout_marginLeft="18dp"
            android:text="@string/now_pay"/>
    </LinearLayout>
</LinearLayout>

到这里布局代码上完了 需要注意3点
1、ScrollView 必须嵌套 线性布局
2、android:layout_weight=“1” ScrollView属性中加入权重 这样才能把底部布局显示出来 不然会溢出
3、android:gravity=“bottom” 这个属性是底部 最外层布局加的 固定底部
在简单的给个布局



//滚动布局中的东西



//底部布局东西

</LinearLayout>

猜你喜欢

转载自blog.csdn.net/weixin_43148719/article/details/83176388