MainActivity.java
transition = new TransitionDrawable(new Drawable[]{
new ColorDrawable(Color.TRANSPARENT),
new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.face1))
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
imageView.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.default_image, null));
}
imageView.setImageDrawable(transition);
transition.startTransition(3000);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
imageView.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.iv1_selector, null));
Log.d("LOG", "CALLED");
}
}
}, 3000);
iv1_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:enterFadeDuration="@android:integer/config_shortAnimTime"
android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:drawable="@drawable/iv_focused_drawable" android:state_focused="true" />
<item android:drawable="@drawable/iv_not_focused_drawable" android:state_focused="false" />
</selector>
我给imageView一个小动画,过渡。完成动画后,应使用处理程序内的选择器绘制更改imageView的背景。但是,由于某些原因,它的背景未应用,但是当我单击imageView时,它将被应用。我不知道处理程序内部发生了什么。对此案有何建议?
这是转换完成后的样子
但正如你所看到的那样,我想让它周围有边框。我不明白为什么它的背景不适用于处理程序