2011-12-15 54 views
0

在ImageView的我已经设置了圆角的边框为象下面这样:Android:如何在这种情况下设置选择器xml?

<ImageView 
        android:id="@+id/twsbiLogoButton" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:layout_gravity="right" 
        android:src="@drawable/tp_twsbi_logo" 
        android:background="@drawable/logo_layout_border"></ImageView> 

其中的背景是xml文件,如:

<?xml version="1.0" encoding="UTF-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <stroke 
     android:width="1dip" 
     /> 
    <solid 
     android:color="#3D2A1D"/> 
    <corners 
     android:radius="20sp" 
     android:topRightRadius="0dp" 
     android:bottomLeftRadius="0dp" 
     android:bottomRightRadius="0dp"/> 

</shape> 

,但我也想给选择到ImageView的就那么如何podssible?

回答

1

你在谈论重点吗?

android:focusable="true" 
+0

不,亲爱的,我的意思是,我们将选择器放在按钮背景上,在我们预设它的时候生效。就像我想为我的imageView一样。如果用户按下它,应该改变颜色。 –

1

我们可以通过使用LayerList做的只是创建一个像多了一个XML的

<?xml version="1.0" encoding="UTF-8"?> 

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
<item> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <stroke 
     android:width="1dip" 
     /> 
    <solid 
     android:color="#3D2A1D"/> 
    <corners 
     android:radius="20sp" 
     android:topRightRadius="0dp" 
     android:bottomLeftRadius="0dp" 
     android:bottomRightRadius="0dp"/> 
</shape> 
</item> 

/*现在,添加您在选择使用更多的项目*/

<item android:drawable="@drawable/postbutton_press" android:state_pressed="true"/> 
<item android:drawable="@drawable/postbutton_press" android:state_focused="true"/> 
<item android:drawable="@drawable/postbutton_normal"/> 

</layer-list> 

现在将这个可绘图添加到Imageview/Button的android:background。 我没有测试这个。猜猜它会工作!手指交叉! :)...

+0

哈哈哈。 。 。好吧,让我试试看。 –