簡單實現多佈局底部固定顯示+中部滑動 仿Tab底部
阿新 • • 發佈:2018-12-16
如何佈局底部固定顯示!接下來直接上佈局程式碼 重要的有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>