免责声明Android新手。
问题:我的滚动视图溢出到底部的导航栏。
所以我想创建一个使用
BottomNavigationView
的应用。所以我创建了一个父{/ 1}} LinearLayout
方向的父活动,有两个孩子。首先是vertically
,其中片段将驻留在其中。其次是Framelayout
。然后在片段中创建BottomNavigationView
并将应用程序UI放在那里。问题是片段应用程序ui接管(溢出到导航栏)。
这是我的代码。我做错了什么?
这是我的活动代码
ScrollView
这是我的片段代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="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="match_parent"
tools:context="com.evildevelopers.answerpoint.MainActivity">
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/navigation"
android:layout_weight="1">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:menu="@menu/navigation" />
</RelativeLayout>
至于在此处启动片段的代码,它是代码。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:fillViewport="false">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.evildevelopers.answerpoint.StatusFragment"
android:weightSum="1">
<TextView
android:id="@+id/labelStatus"
android:layout_width="152dp"
android:layout_height="wrap_content"
android:text="@string/fragment_status_label_status"
android:textSize="18sp" />
<TextView
android:id="@+id/previousStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<EditText
android:id="@+id/editTextStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/fragment_status_text_status_hint"
android:inputType="text|textLongMessage" />
<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="Switch" />
<DatePicker
android:id="@+id/datePicker"
android:layout_width="match_parent"
android:layout_height="405dp" />
<TimePicker
android:id="@+id/timePicker"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_weight="0.56" />
<Button
android:id="@+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:elevation="0dp"
android:text="@string/fragment_status_btn_save" />
</LinearLayout>
</ScrollView>
答案 0 :(得分:0)
使用Relative Layout
执行此操作。在Frame Layout
中fragments UI
即将开始。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/navigation"
android:layout_alignParentTop="true" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/white"
app:menu="@menu/navigation" />
</RelativeLayout>
答案 1 :(得分:0)
由于您选择的布局,您的BottomNavigationView
看起来很奇怪,因为您使用的背景和内容正在切断。
在下面的修改后的代码中,我删除了BottomNavigationView
上的背景颜色,并进行了一些布局调整,以便FrameLayout
始终呈现在BottomNavigationLayout
之上。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="@menu/bottom_menu" />
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/navigation"/>
</RelativeLayout>
另外,请确保删除weightSum="1"
中LinearLayout
上的ScrollView
设置。我测试了上面的布局,它应该按原样运行。
注意:仅在使用布局时定义权重以避免混淆(可能还有渲染问题)。同时看到你是Android新手,我也建议你阅读Constraint Layouts。这是一个方便的新布局,可以很好地适应您的场景。
答案 2 :(得分:0)
像这样将您的框架布局更改为容器:
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_above="@+id/navigation"
android:layout_weight="1">
FrameLayout
的 0dp 高度将调整剩余的父高度减去底部导航栏的高度。所以你的滚动视图没有再次溢出。