Android内容隐藏的java底部导航
在我第一次尝试Android(Studio 3.0)时,我成功地实现了bottom navigation和fragments
现在,当在第一个片段上实现小部件时,我意识到底部导航覆盖/隐藏了片段的最下部
该片段由两个布局、一个listview和两个按钮组成:
<FrameLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
tools:context="com.example.xyz.ticketvendor.QuickRideFragment">
<!-- TODO: Update blank fragment layout -->
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:orientation="vertical"
>
<ListView
安卓:id="@+id/lvTransportLines"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
/>
<LinearLayout
安卓:id="@+id/buttons"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="horizontal"
安卓:layout_alignBottom="@id/lvTransportLines">
<Button
安卓:id="@+id/getTicket"
安卓:layout_width="0dp"
安卓:layout_height="120dp"
安卓:layout_weight=".75"
安卓:text="Get Ticket" >
</Button>
<Button
安卓:id="@+id/setDefaultSMSApp"
安卓:layout_width="0dp"
安卓:layout_height="120dp"
安卓:layout_weight=".25"
安卓:text="Reset" >
</Button>
</LinearLayout>
</RelativeLayout>
如您所见,我正在使用安卓:layout_alignBottom="@id/lvTransportLines"
将LinearLayout(保留两个按钮)放置在Listview下方。
我之所以能看到这些按钮,是因为我把它们的高度设置为某个巨大的东西,以供测试之用
但是-我可以使用哪个布局属性将LinearLayout定位到足够高的位置,以避免被底部导航隐藏?谢谢
更新 在实施@Nero的解决方案后,我想到了以下几点:
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
tools:context="com.example.antibala.ticketvendor.QuickRideFragment"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
>
<ListView
安卓:id="@+id/lvTransportLines"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
/>
<LinearLayout
安卓:id="@+id/buttons"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="horizontal"
安卓:layout_alignParentBottom="true"
>
<Button
安卓:id="@+id/getTicket"
安卓:layout_width="0dp"
安卓:layout_height="140dp"
安卓:layout_weight=".75"
安卓:text="Get Ticket"
>
</Button>
<Button
安卓:id="@+id/setDefaultSMSApp"
安卓:layout_width="0dp"
安卓:layout_height="140dp"
安卓:layout_weight=".25"
安卓:text="Reset"
>
</Button>
</LinearLayout>
</RelativeLayout>
但我得到的结果和第一张照片完全一样。我做错了什么
主要活动。xml
<?xml version="1.0" encoding="utf-8"?>
<安卓.support.constraint.ConstraintLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:id="@+id/container"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
tools:context="com.example.xyz.ticketvendor.MainActivity">
<FrameLayout
安卓:id="@+id/frameLayout"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_marginLeft="@dimen/activity_horizontal_margin"
安卓:layout_marginStart="@dimen/activity_horizontal_margin"
安卓:layout_marginTop="@dimen/activity_vertical_margin"
安卓:text="@string/title_home"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<安卓.support.design.widget.BottomNavigationView
安卓:id="@+id/navigation"
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:layout_marginEnd="0dp"
安卓:layout_marginStart="0dp"
安卓:background="?安卓:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
</安卓.support.constraint.ConstraintLayout>
# 1 楼答案
将其添加到相对布局或框架布局中
# 2 楼答案
抱歉耽搁了,伙计,我在测试一些东西,不得不从头开始创建这个例子。有趣的是,你只需要在你的主要活动中对框架布局进行一次修改。xml文件
请添加以下属性,它将为您提供所需的设计
按要求更新
主要活动。xml
碎片是空白的。xml
主要活动。爪哇
}