带有2个LinearLayout的布局,每个都有一个屏幕宽度

时间:2012-12-17 18:49:21

标签: android xml android-ui

我正在尝试创建类似于片段允许我们做但没有片段的东西。

我正在尝试创建一个布局(相对或线性,我不知道如何使用它以及如何制作它,我需要一些帮助)并在其中放入另外3个LinearLayout。

3个LinearLayouts中的每一个都应该有屏幕宽度,我试图使用xml,没有代码,因为当我尝试使用代码调整布局大小时,我遇到了很多麻烦,因为在onCreate上没有测量布局

然后我将touchListener设置为大布局并创建类似于片段的东西。

有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

  

“我正在尝试创建类似于片段允许的内容   做但没有碎片。“

片段有自己的生命周期,是“活动的模块化部分”。与他们一个重要的想法是,您可以在不同的配置中重复使用部分活动。它们比嵌套布局(或者您计划在其间切换的触摸侦听器的视图,如ViewSwitcher?)强大得多。我不会尝试重新创建片段,只使用片段?

http://developer.android.com/guide/components/fragments.html

  

“我正在尝试创建一个布局(相对或线性,我不知道   一个使用和如何制作,我需要一些帮助)和放   其中有3个LinearLayout。“

我不确定我是否理解这个问题,但相对布局或线性布局都可以包含其他布局。一个简单的例子(注意,这不一定是一个有效的布局,它只是根据问题嵌套它们的一个例子):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#cccccc"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ONE" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#dddddd"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TWO" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#696969"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="THREE" />
    </LinearLayout>

</LinearLayout>

这会在典型的窗口(活动)中创建以下内容:

enter image description here