我在 HorizontalScrollView 中有 RelativeLayouts。当用户单击其中一个布局(或其任何子布局)时,我需要更改特定 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>
谢谢, 西蒙
最佳答案
如果您想使用您在 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>
关于android - 如何处理属于 HorizontalScrollView 的 RelativeLayout 上的 onClick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13673586/