调用布局View的performClick()方法

修改之前的xml片段。

            <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/layout_deletesms"
                android:clickable="true"
                android:padding="0dip"
                android:background="@drawable/sms_dialog_button"
                android:layout_width="50dip"
                android:layout_height="match_parent" >
                <ImageView
                    android:id="@+id/deleteSms"
                    android:layout_centerInParent="true"
                    android:src="@drawable/sms_delete"
                    android:scaleType="centerInside"
                    android:focusable="false" // 仅仅这样设置无法实现所需效果。
                    android:background="#00000000"
                    android:layout_width="30dip"
                    android:layout_height="30dip"/>
             </RelativeLayout>
实现效果:点击ImageView时,ImageView的容器对象RelativeLayout,也有被点击的效果出现。

这里,布局被点击时的效果是,切换不同的drawable图片。

在xml布局文件中,无论怎么改都达不到效果。

最后采取在代码中实现。当点击ImageView时,调用布局View的performClick()方法。

            <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/layout_deletesms"
                android:clickable="true"
                android:padding="0dip"
                android:background="@drawable/sms_dialog_button"
                android:layout_width="50dip"
                android:layout_height="match_parent" >
                <ImageView
                    android:id="@+id/deleteSms"
                    android:layout_centerInParent="true"
                    android:src="@drawable/sms_delete"
                    android:scaleType="centerInside"
                    android:background="#00000000"
                    android:layout_width="30dip"
                    android:layout_height="30dip"/>
             </RelativeLayout>

mLayoutDelsms = (RelativeLayout) findViewById(R.id.layout_deletesms);

case R.id.deleteSms:
    mLayoutDelsms.performClick();

posted on 2013-07-18 19:08  勤修  阅读(5492)  评论(0编辑  收藏  举报

导航