1

Horizo​​ntalScrollView に RelativeLayouts があります。ユーザーがレイアウトの 1 つ (またはその子) をクリックすると、特定の RelativeLayout の背景色を変更し、さらに処理するためにその ID を取得する必要があります。これは、DuplicateParentState または onTouchEvent を使用して実行できることがわかりました。おすすめの方法は?

提案どおりに XML ファイルを編集した後の私の XML ファイル:

<RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
            <youme.appyoume.com.ExDialog>

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:clickable="true"
                android:duplicateParentState="true"
                android:onClick="onClick"
                android:src="@drawable/ic_launcher" />

            <EditText
                android:id="@+id/TextView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginTop="20dp"
                android:layout_weight="1"
                android:duplicateParentState="true"
                android:ems="10"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:inputType="textMultiLine"
                android:text="text" >

                <requestFocus />
            </EditText>
            </youme.appyoume.com.ExDialog>
        </RelativeLayout>

ありがとう、サイモン

4

2 に答える 2

2

xmlで作成したカスタムクラスを使用する場合は、オブジェクトのルート名全体を使用するだけです。たとえば、クラスがある場合

com.your.package.customButton

あなたはあなたのxmlに書くでしょう

<RelativeLayout
   ...layoutstuff config>

  <com.your.package.customButton
    ...customButton layout config/>

</RelativeLayout>

相対レイアウトをサブクラス化する場合は、次のように使用します

<youme.appyoume.com.ExDialog
    ...layout setup stuff>

    <Button
     ...button setup stuff
    />

 </youme.appyoume.com.ExDialog>
于 2012-12-06T18:08:11.263 に答える
0

setTagとgetTagを使用して、将来の参照用にいつでもタグを割り当て、setOn Click Listenerを使用して、必要なものをそこに配置することができます。

于 2012-12-02T21:02:15.250 に答える