私の状況は次のとおりです。私Activity
は3つの主要な部分を含むものを持っています。このアクティビティの上部には、2つのツールパネルがありますImageButtons
。アクティビティの下部には、上部と同様のツールパネルもあります。
LinearLayout
このアクティビティの主なコンポーネントは、3x3ImageButtons
グリッドを含む画面の中央にあります。コンテキストを取得するために、これらのグリッドボタンの目的を簡単に説明します。
この3x3グリッドは、特定の日のこのボタンの状態(トグルボタンとその状態がオン/オフであるとしましょう)を示します。したがって、ある日、3x3のセットが1つあり、これらには特定の日の独自の状態があります。
今私が達成しようとしているのは、ユーザーがグリッド間または日付間をそれぞれスクロールできる機能を持つことです。私の考えはViewFlipper
、アクティビティの主要コンポーネントとして(ではなくLinearLayout
)、ボタンの1つ以上のグリッドを使用することです。これは私がすでに持っているものです。3x3を別の3x3(状態付き)に別の日に切り替えることができます。このために、3x3グリッドXML定義をコピーして貼り付け、これを子として配置してフリッパーを表示します(x回)。
私の考えは、3x3の定義を1つ作成し、それをある種のテンプレートのようにx回再利用することです。これにより、「別の3x3をこの日に使用したいので、これを次のように追加したい」と言うことができます。次の子ViewFlipper
」。
この目的のために(3x3のコンポーネントを持つために)私は単に拡張するクラスをLinearLayour
作成し、その中でボタンの3x3定義を生成/再利用したいと思います。確かに私はこの新しいクラスのJavaコードでそれを行うことができますが、xmlを再利用することでそれを行う方法はありますか(これは維持して読む方が良いです)?
使ってみましLayoutInflater
たが、これはおそらく私が探しているものではありません。
前もって感謝します
編集
これがフリッパー付きのメインレイアウトのコードです
<ViewFlipper android:id="@+id/view_flip"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#FF0000">
<!-- Here goes 9x9 cubbie layout programaticaly -->
</ViewFlipper>
このフィッパーに、このレイアウトでビューを追加します(このコードはLayoutInflaterを介して割り当てられます)。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/background" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" android:gravity="center">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="vertical">
<ImageButton android:id="@+id/life_att_1" style="@style/AttributeButton" />
<TextView android:id="@+id/life_att_text_1" android:text="test"
style="@style/AttributeText" />
</LinearLayout>
...
</LinearLayout>
...
</LinearLayout>
編集2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/background" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:layout_weight="1" android:paddingLeft="16dip">