0

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

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

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

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

有人能帮助我吗?

4

1 回答 1

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>

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

在此处输入图像描述

于 2012-12-17T19:30:35.963 回答