【问题标题】:How do I fix a layout at bottom and at top without hiding elements on Android?如何修复底部和顶部的布局而不在 Android 上隐藏元素?
【发布时间】:2018-02-11 04:52:38
【问题描述】:

我在使用RelativeLayout、ScrollView 和一些LinearLayout 来让一些元素始终位于顶部和一些可滚动的东西时遇到问题。

这是我的 XML

https://pastebin.com/Uai2UynP

(我不知道为什么它在这篇文章中被分开,但它是相同的代码) 关键是,当我将android:alignParentBottom="true" 添加到具有“始终位于顶部栏”的RelativeLayout 时,它隐藏了我上面的ScrollView 的一部分。这可以通过在上面的 ScrollView 中添加 android:PaddingBottom="[something]" 来解决,但是这样做会在顶部隐藏一些东西,因为我基本上拥有带有电子邮件、黄金和硬币的 LinearLayout,我也希望它们总是在顶部。

【问题讨论】:

    标签: android layout fixed


    【解决方案1】:

    使用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>
    

    【讨论】:

      猜你喜欢
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 2016-02-08
      • 2016-02-03
      • 2021-07-25
      • 2014-09-29
      • 1970-01-01
      相关资源
      最近更新 更多