如何修复底部和顶部的布局而不隐藏 Android 上的元素?
How do I fix a layout at bottom and at top without hiding elements on Android?
我在使用 RelativeLayout、ScrollView 和一些 LinearLayout 来让一些元素始终位于顶部和一些可滚动时遇到问题。
这是我的XML
https://pastebin.com/Uai2UynP
(我不知道为什么它在这个 post 中分开了,但它是相同的代码)
关键是,当我将 android:alignParentBottom="true"
添加到带有 "always on top bar" 的 RelativeLayout 时,它隐藏了上面 ScrollView 的一部分。这可以通过在上面的 ScrollView 中添加一个 android:PaddingBottom="[something]"
来解决,但是这样做会在顶部隐藏一些东西,因为我基本上有带有电子邮件、金币和硬币的 LinearLayout,我也总是想要它。
使用 RelativeLayout 作为主要布局,并在您想要放置顶部的布局中使用 android:layout_alignParentTop="true"
,并在您想要设置底部的下一个布局中使用 android:layout_alignParentBottom="true"
。我给你举个例子,
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true">
</RelativeLayout>
</RelativeLayout>
我在使用 RelativeLayout、ScrollView 和一些 LinearLayout 来让一些元素始终位于顶部和一些可滚动时遇到问题。
这是我的XML
https://pastebin.com/Uai2UynP
(我不知道为什么它在这个 post 中分开了,但它是相同的代码)
关键是,当我将 android:alignParentBottom="true"
添加到带有 "always on top bar" 的 RelativeLayout 时,它隐藏了上面 ScrollView 的一部分。这可以通过在上面的 ScrollView 中添加一个 android:PaddingBottom="[something]"
来解决,但是这样做会在顶部隐藏一些东西,因为我基本上有带有电子邮件、金币和硬币的 LinearLayout,我也总是想要它。
使用 RelativeLayout 作为主要布局,并在您想要放置顶部的布局中使用 android:layout_alignParentTop="true"
,并在您想要设置底部的下一个布局中使用 android:layout_alignParentBottom="true"
。我给你举个例子,
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true">
</RelativeLayout>
</RelativeLayout>