調用布局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();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM