如何删除 Android 中不需要的重叠

发布于 2024-12-13 15:43:57 字数 2018 浏览 3 评论 0原文

我正在尝试制作一个 Android 界面,但我在视图方面遇到了一些重叠问题。

这是我的代码。它在一个选项卡中,但我把选项卡部分剪掉了。如果你需要的话我会添加的。

更新:我忘了写我有很多 TextView,而不仅仅是一个

<FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <ScrollView
                android:orientation="vertical"
                android:layout_height="fill_parent"
                android:layout_width="fill_parent">

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_height="fill_parent"
                    android:layout_width="fill_parent">

                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true" />

                <!-- A lot of TextView as the one above -->

                </LinearLayout>
            </ScrollView>

            <RelativeLayout
                android:id="@+id/InnerRelativeLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true" >

                <Button
                     android:id="@+id/add"
                     android:layout_height="wrap_content"
                     android:layout_alignParentRight="true"
                     android:layout_width="fill_parent"
                     android:text="@string/add" />
            </RelativeLayout>
        </RelativeLayout>
    </FrameLayout>

这就是它的输出。正如您所看到的,在底部,文本位于按钮后面,但我希望它们有两种不同的布局

Screenshot

I am trying to make an Android interface, but I have a little overlapping issue with the views.

Here is my code. It is in a Tab, but I cut the Tab-part away. If you need it, I'll add it.

UPDATE: I forgot to write that I have a lot of TextView, not only one

<FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <ScrollView
                android:orientation="vertical"
                android:layout_height="fill_parent"
                android:layout_width="fill_parent">

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_height="fill_parent"
                    android:layout_width="fill_parent">

                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true" />

                <!-- A lot of TextView as the one above -->

                </LinearLayout>
            </ScrollView>

            <RelativeLayout
                android:id="@+id/InnerRelativeLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true" >

                <Button
                     android:id="@+id/add"
                     android:layout_height="wrap_content"
                     android:layout_alignParentRight="true"
                     android:layout_width="fill_parent"
                     android:text="@string/add" />
            </RelativeLayout>
        </RelativeLayout>
    </FrameLayout>

And this is what it outputs. As you can see, in the bottom, the text goes behind the button, but I want to have them in two different layouts

Screenshot

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

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

发布评论

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

评论(2

挖鼻大婶 2024-12-20 15:43:57

尝试将其相对放置在按钮上方。

<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <ScrollView                
            android:orientation="vertical"
            android:layout_above="@+id/InnerRelativeLayout" //Add this
            android:layout_height="fill_parent"
            android:layout_width="fill_parent">

            <LinearLayout
                android:orientation="vertical"
                android:layout_height="fill_parent"
                android:layout_width="fill_parent">

            <TextView
                android:text="welcome"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true" />

            </LinearLayout>
        </ScrollView>

        <RelativeLayout
            android:id="@+id/InnerRelativeLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" >

            <Button
                 android:id="@+id/add"
                 android:layout_height="wrap_content"
                 android:layout_alignParentRight="true"
                 android:layout_width="fill_parent"
                 android:text="@string/add" />
        </RelativeLayout>
    </RelativeLayout>
</FrameLayout>

Try to position it relatively above the button.

<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <ScrollView                
            android:orientation="vertical"
            android:layout_above="@+id/InnerRelativeLayout" //Add this
            android:layout_height="fill_parent"
            android:layout_width="fill_parent">

            <LinearLayout
                android:orientation="vertical"
                android:layout_height="fill_parent"
                android:layout_width="fill_parent">

            <TextView
                android:text="welcome"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true" />

            </LinearLayout>
        </ScrollView>

        <RelativeLayout
            android:id="@+id/InnerRelativeLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" >

            <Button
                 android:id="@+id/add"
                 android:layout_height="wrap_content"
                 android:layout_alignParentRight="true"
                 android:layout_width="fill_parent"
                 android:text="@string/add" />
        </RelativeLayout>
    </RelativeLayout>
</FrameLayout>
柠檬 2024-12-20 15:43:57

除非绝对必要,否则不要使用RelativeLayout。曾经。我知道这不是一个流行的观点,但我就是这么告诉大家的。

我假设您希望滚动条占据尽可能多的空间,然后将按钮放在底部?

<LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical">

            <ScrollView
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:layout_weight="1">
                <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:orientation="vertical">
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>

                </LinearLayout>
            </ScrollView>

                <Button
                     android:id="@+id/add"
                     android:layout_height="wrap_content"
                     android:layout_width="fill_parent"
                     android:text="@string/add" />

        </LinearLayout>

我认为您可以将 LinearLayout 转储到 ScrollView 中,假设您只有 1 个子级(TextView)

Don't use RelativeLayout unless you absolutely have to. Ever. I know that's not a popular opinion, but that's what I tell everybody.

I assume you want the scroll to take up as much space as possible, then have the button at the bottom?

<LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical">

            <ScrollView
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:layout_weight="1">
                <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:orientation="vertical">
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:text="welcome"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>

                </LinearLayout>
            </ScrollView>

                <Button
                     android:id="@+id/add"
                     android:layout_height="wrap_content"
                     android:layout_width="fill_parent"
                     android:text="@string/add" />

        </LinearLayout>

I think you can dump the LinearLayout inside the ScrollView, assuming you only have 1 child (the TextView)

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