如何让下方导航栏显示activity中的最后一项?
How to make the lower navigation bar show what's the last thing in the activity?
我试图制作一个较低的导航栏,因为我需要使用滚动视图的视图很多,但问题是由于导航栏,滚动视图中的最后一个元素没有出现。
那么我该怎么做才能使最后一个元素出现?
我的 xml 代码是:
<?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:background="#E6E6E6"
android:layout_height="match_parent"
tools:context=".mainPage">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:fontFamily="@font/lato_bold"
android:text="Servings"
android:textColor="@color/purple_700"
android:textSize="20sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:inputType="number"
android:id="@+id/servings"
android:hint="Servings that you will eat"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:fontFamily="@font/lato_bold"
android:text="grams per serving"
android:textColor="@color/purple_700"
android:textSize="20sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:inputType="number"
android:id="@+id/grams"
android:hint="grams per serving"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:fontFamily="@font/lato_bold"
android:text="calories for each serving"
android:textColor="@color/purple_700"
android:textSize="20sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:inputType="number"
android:id="@+id/calories"
android:hint="calories for each serving"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:fontFamily="@font/lato_bold"
android:text="meal name"
android:textColor="@color/purple_700"
android:textSize="20sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:inputType="text"
android:id="@+id/name"
android:hint="type the meal name"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/add"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="@font/lato_bold"
android:text="Add"
android:textSize="14sp" />
<Button
android:id="@+id/dont"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="@font/lato_bold"
android:text="Don’t know how many calories are in this meal ?"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<Button
android:id="@+id/main_food"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="@font/lato_bold"
android:text="What have you eaten today"
android:textSize="14sp" />
<Button
android:id="@+id/adding_food"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="@font/lato_bold"
android:text="Food Adding"
android:textSize="14sp" />
<Button
android:id="@+id/profile_food"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="@font/lato_bold"
android:text="Profile"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
所以我怎样才能在滚动视图中制作最后一个元素,因为导航栏阻止了它(它在它的前面所以最后一个元素不显示。
This is an image of it and as you can see the navigation bar is in the front of the last element so it doesn't show because of that
将 android:paddingBottom = "Xdp"
添加到最后一个 LinearLayout,其中 X
比您的底栏大。
示例:android:paddingBottom = "30dp"
将id
添加到底部导航栏LinearLayout
将 android:layout_above="@+id/yourbottomlayoutid"
、android:layout_height="match_parent"
和 android:fillViewport="true"
添加到您的 ScrollView
。
参考以下代码:
<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:background="#E6E6E6"
android:layout_height="match_parent"
tools:context=".mainPage">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_above="@+id/llBottomBar">
<!--Your LinearLayout-->
</ScrollView>
<LinearLayout
android:id="@+id/llBottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<!--Bottom navigation bar buttons-->
</LinearLayout>
</RelativeLayout>
我试图制作一个较低的导航栏,因为我需要使用滚动视图的视图很多,但问题是由于导航栏,滚动视图中的最后一个元素没有出现。 那么我该怎么做才能使最后一个元素出现? 我的 xml 代码是:
<?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:background="#E6E6E6"
android:layout_height="match_parent"
tools:context=".mainPage">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:fontFamily="@font/lato_bold"
android:text="Servings"
android:textColor="@color/purple_700"
android:textSize="20sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:inputType="number"
android:id="@+id/servings"
android:hint="Servings that you will eat"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:fontFamily="@font/lato_bold"
android:text="grams per serving"
android:textColor="@color/purple_700"
android:textSize="20sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:inputType="number"
android:id="@+id/grams"
android:hint="grams per serving"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:fontFamily="@font/lato_bold"
android:text="calories for each serving"
android:textColor="@color/purple_700"
android:textSize="20sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:inputType="number"
android:id="@+id/calories"
android:hint="calories for each serving"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:fontFamily="@font/lato_bold"
android:text="meal name"
android:textColor="@color/purple_700"
android:textSize="20sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:inputType="text"
android:id="@+id/name"
android:hint="type the meal name"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/add"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="@font/lato_bold"
android:text="Add"
android:textSize="14sp" />
<Button
android:id="@+id/dont"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="@font/lato_bold"
android:text="Don’t know how many calories are in this meal ?"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<Button
android:id="@+id/main_food"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="@font/lato_bold"
android:text="What have you eaten today"
android:textSize="14sp" />
<Button
android:id="@+id/adding_food"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="@font/lato_bold"
android:text="Food Adding"
android:textSize="14sp" />
<Button
android:id="@+id/profile_food"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:fontFamily="@font/lato_bold"
android:text="Profile"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
所以我怎样才能在滚动视图中制作最后一个元素,因为导航栏阻止了它(它在它的前面所以最后一个元素不显示。 This is an image of it and as you can see the navigation bar is in the front of the last element so it doesn't show because of that
将 android:paddingBottom = "Xdp"
添加到最后一个 LinearLayout,其中 X
比您的底栏大。
示例:android:paddingBottom = "30dp"
将id
添加到底部导航栏LinearLayout
将 android:layout_above="@+id/yourbottomlayoutid"
、android:layout_height="match_parent"
和 android:fillViewport="true"
添加到您的 ScrollView
。
参考以下代码:
<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:background="#E6E6E6"
android:layout_height="match_parent"
tools:context=".mainPage">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_above="@+id/llBottomBar">
<!--Your LinearLayout-->
</ScrollView>
<LinearLayout
android:id="@+id/llBottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<!--Bottom navigation bar buttons-->
</LinearLayout>
</RelativeLayout>