android - 如何处理属于 Horizo​​ntalScrollView 的 RelativeLayout 上的 onClick

标签 android touch-event horizontalscrollview

我在 Horizo​​ntalScrollView 中有 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 - 如何处理属于 Horizo​​ntalScrollView 的 RelativeLayout 上的 onClick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13673586/

相关文章:

android - 滑动并展开 View Android

android - 如果字符串文本是从右到左写入的,是否可以在 android/Java 中识别?

android - 如何防止一次为多个 View 调用 onTouchEvent() 方法?

android - 如何水平滚动 LinearLayout?

Android - Horizo​​ntalScrollView 不会一直滚动

java - android权限唤醒锁有什么用?

android - 从android中的url流式传输音频/视频文件

ios - 在 SpriteKit 中,touchesBegan 是否在与 SKScene 更新方法相同的线程中运行?

Android GestureDetector 无法使用 FrameLayout 检测到 onScroll 事件

android - Horizo​​ntalScrollView - 计算滑动后的停止位置