如何显示pssed橙色通过一个ImageView的$ P $? [英] How to show pressed orange over an ImageView?
问题描述
我的尺寸相对布局绝对是50dp,只有图像以外的部位都出现,所以图像阻止pssed状态$ P $ ...如何得到我想要的效果吗?和仅供参考,把背景直接在ImageView的改变不了什么;在pressed橙仍然是下方。
< RelativeLayout的
机器人:layout_width =50dp
机器人:layout_height =50dp
机器人:layout_alignParentRight =真
机器人:layout_centerVertical =真
机器人:layout_marginRight =10dp
机器人:背景=@绘制/ btn_orange
机器人:可点击=真正的>
< ImageView的
机器人:ID =@ + ID / preview_plus
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =@绘制/ plus_button/>
< / RelativeLayout的>
和btn_orange.xml:
<?XML版本=1.0编码=UTF-8&GT?;
<选择的xmlns:机器人=http://schemas.android.com/apk/res/android>
<项目的android:STATE_ pressed =真正的>
<彩色机器人:颜色=#66ffb300/>
< /项目>
< /选择>
我必须说,你可以使用(触摸听者)
这款U如何使用触摸听者
图像=(ImageView的)findViewById(R.id.image);
先找到乌尔图片
添加触摸听者以UR图片
image.setOnTouchListener(image_onTouch);
//添加淡淡的方法,它是通过名字image_onTouch
OnTouchListener image_onTouch =新OnTouchListener(){
@覆盖
公共布尔onTouch(查看arg0中,MotionEvent ARG1){
INT iAction = arg1.getAction(); 如果(iAction == 0){
image.setImageResource(R.drawable.image1);
}
其他{
image.setImageResource(R.drawable.image2);
}
返回false;
}
};
//图像1 UR图像,ü要2点击
和图像2是图像,当你触摸的形象,你必须做出的另一幅图像中,背景颜色做ü想告诉和code使用它
I sized the rel layout absolutely to 50dp, and only the parts outside the image are showing, so the image is blocking the pressed state...how to get the effect that I want? And FYI, putting the background directly on the ImageView changes nothing; the pressed orange is still underneath.
<RelativeLayout
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="@drawable/btn_orange"
android:clickable="true" >
<ImageView
android:id="@+id/preview_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/plus_button" />
</RelativeLayout>
and btn_orange.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<color android:color="#66ffb300"/>
</item>
</selector>
I must say you can use a (touch listner) this how u use a touch listner
image=(ImageView)findViewById(R.id.image);
find ur image first
Add a touch Listner to ur image
image.setOnTouchListener(image_onTouch);
//Add a touch method which is by name image_onTouch
OnTouchListener image_onTouch=new OnTouchListener(){
@Override
public boolean onTouch(View arg0,MotionEvent arg1){
int iAction=arg1.getAction();
if(iAction==0){
image.setImageResource(R.drawable.image1);
}
else{
image.setImageResource(R.drawable.image2);
}
return false;
}
};
// image 1 is ur image which u want 2 click and image 2 is the image when you touch that image you have to make an another image in which background color do u wanna show and use it in the code
这篇关于如何显示pssed橙色通过一个ImageView的$ P $?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!