0

私は、フラグメントを使用せずに、フラグメントでできることに似たものを作成しようとしています。

私は1つのレイアウトを作成しようとしています(相対または線形、使用するレイアウトと作成方法がわからない、助けが必要な場所)、その中に別の3つのLinearLayoutを配置します。

コードを使用してレイアウトのサイズを変更しようとしたときに、onCreateで測定されていないレイアウトのために多くの問題が発生したため、コードなしでxmlで作成しようとしています。

次に、大きなレイアウトに touchListener を設定し、フラグメントに似たものを作成します。

誰か助けてくれませんか?

4

1 に答える 1

0

「私は、フラグメントができるものと似たものを作成しようとしていますが、フラグメントはありません。」

フラグメントには独自のライフサイクルがあり、「アクティビティのモジュラーセクション」です。それらの大きなアイデアは、アクティビティの一部をさまざまな構成で再利用できることです。これらは、ネストされたレイアウト(または、ViewSwitcherのように切り替える予定のタッチリスナーを備えたビュー)よりもはるかに強力です。フラグメントを再作成しようとはせず、フラグメントを使用するだけですか?

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

「私は1つのレイアウト(相対的または線形、どちらを使用するか、どのように作成するか、助けが必要な場合)を作成し、その中に別の3つのLinearLayoutを配置しようとしています。」

質問を理解できるかどうかはわかりませんが、相対レイアウトまたは線形レイアウトのいずれかに他のレイアウトを含めることができます。1つの簡単な例(これは必ずしも効率的なレイアウトではないことに注意してください。質問ごとにそれらをネストする例にすぎません):

<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 に答える