首頁 > 軟體

Android如何實現底部選單固定到底部

2020-09-22 21:00:16

今天搞了很久的一個問題,導航選單沒有固定到底部,因為上面是ListView,可是沒內容,於是就浮動上去了。

效果如下:

這裡採用的是一個碎片,程式碼是:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
  >

<TextView
  android:id="@+id/card_title_tv"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@drawable/background_card"
  android:gravity="center"
  android:textSize="18sp"/>

<ListView
  android:id="@+id/jonrney_list_item"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_marginBottom="48dp"
  />
</LinearLayout>

出問題了,百度了很多,試了很多的辦法,沒用。

主頁面程式碼:

<?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"
  xmlns:tl="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/container"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="#eeeeee"
  android:scrollbars="none"
  >

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <!--android:background="@color/colorPrimaryDark"-->
    <!--內容-->
    <FrameLayout
      android:id="@+id/fl_change"
      android:layout_weight="1"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      >
    </FrameLayout>
  <!-- <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/bottom"
    android:layout_alignParentBottom="true" >-->
<!--底部-->
    <com.flyco.tablayout.CommonTabLayout
      android:id="@+id/tl_3"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="#ffffff"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      tl:tl_indicator_gravity="TOP"
      tl:tl_indicator_color="#2C97DE"
      tl:tl_textSelectColor="#2C97DE"
      tl:tl_textUnselectColor="#66000000"
      tl:tl_underline_height="2dp"/>
  <!-- </LinearLayout>-->
    <!--android:layout_alignParentBottom="true"-->
  </LinearLayout>
</android.support.constraint.ConstraintLayout >

最後發現是這段程式碼惹的麻煩:android:layout_height="wrap_content"

也是自己對這個屬性沒有了解清楚,不知道從哪裡copy來的一個程式碼,這個屬性程式碼自動浮動,根據內容更改大小。所以就造成了我現在的情況。

所以改成:android:layout_height="match_parent" 就好了。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援it145.com。


IT145.com E-mail:sddin#qq.com