android imagebutton 点击效果缩小,Android 点击ImageButton时有“按下”的效果的实现

Android 点击ImageButton时有“按下”的效果的实现

1为ImageButton添加图片后,有边框,看起来像是图片贴在了一个按扭上面,要多丑有多丑。

解决办法:ImageButton背景设为透明:#0000

2.使用Button时为了让用户有“按下”的效果,有两种实现方式:

A.

imageButton.setOnTouchListener(new OnTouchListener(){

@Override

public boolean onTouch(View v, MotionEvent event) {

if(event.getAction() == MotionEvent.ACTION_DOWN){

//更改为按下时的背景图片

v.setBackgroundResource(R.drawable.pressed);

}else if(event.getAction() == MotionEvent.ACTION_UP){

//改为抬起时的图片

v.setBackgroundResource(R.drawable.released);

}

return false;

}

});

B.

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

时间: 2017-03-17

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Android Studio中实现ImageView或是点ImageButton实现页面跳转,可以按照以下步骤进行: 1. 在XML布局文件中添加一个ImageView或者ImageButton控件,并设置其id和点事件属性。 2. 在Java代码中找到该控件,并设置其点事件监听器。 3. 在点事件的回调函数中,使用Intent对象跳转到目标页面。 以下是示例代码: XML布局文件: ``` <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image" android:onClick="onImageClick" /> <ImageButton android:id="@+id/imageButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/button" android:onClick="onButtonClick" /> ``` Java代码: ``` public class MainActivity extends AppCompatActivity { private ImageView imageView; private ImageButton imageButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = findViewById(R.id.imageView); imageButton = findViewById(R.id.imageButton); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, ImageActivity.class); startActivity(intent); } }); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, ButtonActivity.class); startActivity(intent); } }); } public void onImageClick(View view) { Intent intent = new Intent(this, ImageActivity.class); startActivity(intent); } public void onButtonClick(View view) { Intent intent = new Intent(this, ButtonActivity.class); startActivity(intent); } } ``` 其中,ImageActivity和ButtonActivity分别是要跳转到的目标页面。在这个例子中,我们实现了两种方法来实现页面跳转:一种是在Java代码中设置点事件监听器,另一种是在XML布局文件中设置onClick属性。无论哪种方法,都需要使用Intent对象来实现页面之间的跳转。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值