Android如何实现底部菜单固定到底部

 更新时间:2020年09月22日 16:29:11   作者:手撕高达的村长  
这篇文章主要介绍了Android如何实现底部菜单固定到底部,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

今天搞了很久的一个问题,导航菜单没有固定到底部,因为上面是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" 就好了。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • Android利用Service开发简单的音乐播放功能

    Android利用Service开发简单的音乐播放功能

    这篇文章主要介绍了Android利用Service开发简单的音乐播放功能,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习吧
    2023-04-04
  • Android 中使用 dlib+opencv 实现动态人脸检测功能

    Android 中使用 dlib+opencv 实现动态人脸检测功能

    完成 Android 相机预览功能以后,在此基础上我使用 dlib 与 opencv 库做了一个关于人脸检测的 demo。接下来通过本文给大家介绍Android 中使用 dlib+opencv 实现动态人脸检测功能 ,需要的朋友可以参考下
    2018-11-11
  • android 中 webview 怎么用 localStorage

    android 中 webview 怎么用 localStorage

    这篇文章主要介绍了android 中 webview 怎么用 localStorage方法的相关资料,需要的朋友可以参考下
    2015-07-07
  • Android 多进程资料总结

    Android 多进程资料总结

    这篇文章主要介绍了Android 多进程资料总结的相关资料,需要的朋友可以参考下
    2016-09-09
  • Android仿iOS侧滑退出当前界面功能

    Android仿iOS侧滑退出当前界面功能

    这篇文章主要为大家详细介绍了Android仿iOS侧滑退出当前界面功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-12-12
  • Android线程的优先级设置方法技巧

    Android线程的优先级设置方法技巧

    对于Android平台上的线程优先级设置来说可以处理很多并发线程的阻塞问题,比如很多无关紧要的线程会占用大量的CPU时间,虽然通过了MultiThread来解决慢速I/O但是合理分配优先级对于并发编程来说十分重要
    2016-02-02
  • Android 为ListView添加分段标头的方法

    Android 为ListView添加分段标头的方法

    下面小编就为大家带来一篇Android 为ListView添加分段标头的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-04-04
  • Android开发之背景动画简单实现方法

    Android开发之背景动画简单实现方法

    这篇文章主要介绍了Android开发之背景动画简单实现方法,涉及Android背景动画简单设置与使用技巧,需要的朋友可以参考下
    2017-10-10
  • Android Studio启动报错Java 1.8 or later is required的解决方法

    Android Studio启动报错Java 1.8 or later is required的解决方法

    这篇文章主要为大家详细介绍了Android Studio启动时报错Java 1.8 or later is required的解决方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-03-03
  • Android项目实战之ListView悬浮头部展现效果实现

    Android项目实战之ListView悬浮头部展现效果实现

    这篇文章主要给大家介绍了Android项目实战之ListView悬浮头部展现效果实现的相关资料,文中通过实例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2022-01-01

最新评论