将滚动视图排列在线性布局上方且不重叠

发布于 2025-01-05 00:37:30 字数 1950 浏览 1 评论 0原文

我需要在水平线性布局上方有一个滚动视图。我的根布局是相对布局(但我可以根据您的解决方案更改它)。

看一下:

// +-----------+
// |           |
// |    A      |
// |           |
// +-----------+
// |    B      |
// +-----------+

B 是布局底部的线性菜单,水平居中对齐。
A 包含一些可能与 B 区域重叠的选项。

我的布局 xml (经过简化)是这样的:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/view1"
            android:layout_above="@+id/bottom_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:orientation="vertical"
            android:visibility="invisible" 
            android:layout_weight="1">
        </LinearLayout>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/view2"
            android:layout_above="@+id/bottom_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:orientation="vertical"
            android:visibility="invisible" 
            android:layout_weight="1">
        </LinearLayout>
        <LinearLayout
            android:id="@+id/bottom_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_margin="5dp"
            android:orientation="horizontal"
            android:padding="5dp" >
        </LinearLayout>
</RelativeLayout> 

我应该怎么做才能避免这种情况?

I need to have a scroll view above a horizontal linear layout. My root layout is relative layout (but I can change it based on your solution).

Look at this:

// +-----------+
// |           |
// |    A      |
// |           |
// +-----------+
// |    B      |
// +-----------+

B is a linear menu at the bottom of layout and aligned horizontally center.
A contains some options that may overlaps B area.

my layout xml (with simplification) is something like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/view1"
            android:layout_above="@+id/bottom_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:orientation="vertical"
            android:visibility="invisible" 
            android:layout_weight="1">
        </LinearLayout>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/view2"
            android:layout_above="@+id/bottom_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:orientation="vertical"
            android:visibility="invisible" 
            android:layout_weight="1">
        </LinearLayout>
        <LinearLayout
            android:id="@+id/bottom_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_margin="5dp"
            android:orientation="horizontal"
            android:padding="5dp" >
        </LinearLayout>
</RelativeLayout> 

What should I do to avoid this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷乱花海 2025-01-12 00:37:30

处理完这个问题后,我发现我应该使用边距!

解决办法是:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/acroll1"
    android:layout_height="wrap_content" 
    android:layout_weight="1"
    android:layout_width="fill_parent"
    android:layout_marginBottom="90dp">

90dp是B区带边距的实际尺寸。

我知道这不是一个真正的解决方案,但它对我来说效果很好,这可能对其他人有帮助。

After dealing with the problem, I figured out that I should use margins!

The solution is:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/acroll1"
    android:layout_height="wrap_content" 
    android:layout_weight="1"
    android:layout_width="fill_parent"
    android:layout_marginBottom="90dp">

90dp is the actual size of B area with margins.

I know that this is not a real solution but it works fine for me and this may help someone else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文