简体   繁体   English

父 LinearLayout 中的 RelativeLayout

[英]RelativeLayout inside a parent LinearLayout

Here is the structure of the layout of my application:这是我的应用程序布局的结构:

<LinearLayout>
    <TabHost>
        <LinearLayout>
            <LinearLayout>
                <TabWidget />
                <FrameLayout />
            </LinearLayout>
        </LinearLayout>
    </TabHost>
</LinearLayout>

The above layout works perfectly.上面的布局完美地工作。 I want to add a textview to show a text in the bottom of the screen.我想添加一个 textview 以在屏幕底部显示文本。 So for showing the text always in the bottom of the screen, I need to create a relative layout.因此,为了始终在屏幕底部显示文本,我需要创建一个相对布局。

I have created a RelativeLayout and placed the textview inside the RelativeLayout like this:我创建了一个 RelativeLayout 并将 textview 放置在 RelativeLayout 中,如下所示:

<RelativeLayout>
    <TextView />
</RelativeLayout>

How can I add this to the original view.如何将其添加到原始视图中。 I have tried several ways to add but nothing works: :(我尝试了几种添加方法,但没有任何效果::(

My aim is to a show a text in the bottom of the screen.我的目标是在屏幕底部显示一个文本。 Is there any way to do this using any layout.有没有办法使用任何布局来做到这一点。

Add the RelativeLayout beneath the TabHost, make the parent LinearLayout also relative and make the child one android:layout_alignInParentBottom="true"在 TabHost 下添加 RelativeLayout,使父 LinearLayout 也是相对的,并使子成为一个 android:layout_alignInParentBottom="true"

Taken from: ListView with Footer Item and adapted取自: ListView with Footer Item并改编

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="vertical"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       >
        <LinearLayout
            android:id="@+id/bottom_view"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true">
                <!--Put whatever view item you want here -->
                <TextView
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                />
       </LinearLayout>
       <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/bottom_view"
       >
        <TabHost>
            <LinearLayout>
                <LinearLayout>
                    <TabWidget />
                    <FrameLayout />
                </LinearLayout>
            </LinearLayout>
        </TabHost>
    </LinearLayout>
  </RelativeLayout>

But I'm sure there's a nicer way to do it with the amount of nested layouts you have.但我确信有一个更好的方法来处理你拥有的嵌套布局的数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM