【问题标题】:RelativeLayout inside a parent LinearLayout父 LinearLayout 中的 RelativeLayout
【发布时间】:2011-05-03 12:17:53
【问题描述】:

这是我的应用程序的布局结构:

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

上述布局完美运行。我想添加一个文本视图以在屏幕底部显示文本。因此,为了始终在屏幕底部显示文本,我需要创建一个相对布局。

我创建了一个 RelativeLayout 并将 textview 放置在 RelativeLayout 中,如下所示:

<RelativeLayout>
    <TextView />
</RelativeLayout>

如何将其添加到原始视图中。我尝试了几种添加方法,但没有任何效果! :(

我的目标是在屏幕底部显示一个文本。有没有办法使用任何布局来做到这一点。

【问题讨论】:

  • 您无法从您提供的信息中回答您的问题,也许可以添加布局外观和外观的屏幕截图?
  • @Blundell 我已经编辑了我的问题。请看一看。
  • 有几种方法可以做到这一点:使用RelativeLayout并使文本视图与底部对齐;使用垂直 LinearLayout 并以这样的方式定义权重,即 TextView 在底部占据所需空间,其余空间由其他视图占用。我不确定我是否完全理解您的问题以更具体
  • 这里是用 ListView 做的,你显然可以为上面的复杂布局更改 Listview:anddev.org/code-snippets-for-android-f33/…
  • 谢谢! Asahi 和 Blundell 我会看看这个......

标签: android layout android-layout android-linearlayout android-relativelayout


【解决方案1】:

在TabHost下面添加RelativeLayout,使父LinearLayout也为relative,子为一个android:layout_alignInParentBottom="true"

【讨论】:

    【解决方案2】:

    取自: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>
    

    但我确信有一个更好的方法来处理你拥有的嵌套布局的数量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-03
      • 1970-01-01
      • 2023-03-18
      相关资源
      最近更新 更多