我有两张想要褪色的图像.最初他们都使用imageview.然后我使用.getDrawable()来获取图像的drawable.
这是我使用的代码
Drawable backgrounds[] = new Drawable[2];
backgrounds[0] = BackgroundImage.getDrawable();
backgrounds[1] = BackgroundImageBlurred.getDrawable();
TransitionDrawable crossfader = new TransitionDrawable(backgrounds);
crossfader.startTransition(3000);
Run Code Online (Sandbox Code Playgroud)
它只显示第一个数组元素上的图像,无论如何它都显示,因为两个图像都设置为在XML中可见.
转型没有开始
任何帮助,将不胜感激 :)
我有这个代码来交叉淡化ImageView的背景:
private void setWithCrossfade(Bitmap bitmap) {
//create drawable vector
Drawable backgrounds[] = new Drawable[2];
//getting first image
backgrounds[0] = mImageView.getDrawable();
backgrounds[1] = new BitmapDrawable(mImageView.getResources(), bitmap);
TransitionDrawable transitionDrawable = new TransitionDrawable(backgrounds);
transitionDrawable.setCrossFadeEnabled(true);
mImageView.setAdjustViewBounds(false);
mImageView.setImageDrawable(transitionDrawable);
//it is needed to reset scale type
mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//start crossfading
transitionDrawable.startTransition(250);
}
Run Code Online (Sandbox Code Playgroud)
ImageView scaleType
设置为centerCrop
XML布局.但是,当交叉淡入淡出完成时,新位图设置为fitXY
.在其他线程中,他们说可以通过重置来解决scaleType
,但它也不起作用.在内存方面,调整位图大小不是一个合适的解决方案.有没有解决方法来实现这个?非常感谢你.
PS:请不要建议交叉淡化2个ImageViews,或者使用ViewSwitcher谢谢.
android android-animation transitiondrawable android-drawable android-bitmap
我有一个TransitionDrawable.这两个状态都是9个补丁并且定义了内容区域.问题是利润率太高 - 实际上它基本上是应有的两倍.似乎它增加了两个九个补丁的边缘.
如果我将这九个补丁中的一个直接设置为背景并且不使用TransitionDrawable,那么边距可以正常工作,因此九个补丁肯定是正确的.
有没有人遇到这样的问题?
编辑:如果我将内容区域设置为资产的完整大小,并在xml中定义填充,它的工作原理.相反,它总是会让保证金错误.这似乎是Android中的一个错误,所以这似乎是唯一的解决方案,但也许有一个更好的解决方法:/
android nine-patch android-ui android-layout transitiondrawable
我有一个ImageView设置为片段的背景(imageview在宽度和高度上都设置为match_parent),scaletype设置为centerCrop.我下载了一个异步放入的图像,并在完成下载后使用TransitionDrawable进行交叉淡入淡出.
第一次使用正确的缩放类型显示图像,但是如果我导航到另一个片段然后以imageview作为背景返回到此片段,则图像显示为变形/拉伸(看起来像imageView设置为fitXY)
如果我不使用TransitionDrawable,图像会保持原样.
是否有一个可保持正确宽高比的TransitionDrawable等效项?或者我是否需要在TransitionDrawable上设置以防止此大小调整?
我真正想做的就是在图像之间进行很好的转换.我想只要将图像设置为TransitionDrawable的第二层drawable一旦完成动画,但是没有办法监视动画何时完成...
编辑:我以为我会提到图像尺寸不一样,不确定这是否有所不同
编辑2:这是设置drawable的代码:
//code above to download image
BitmapDrawable bitmapDrawable = new BitmapDrawable(imageview.getResources(), bitmap);
TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[]{imageview.getDrawable(), bitmapDrawable});
imageview.setImageDrawable(transitionDrawable);
transitionDrawable.startTransition(300);
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用TransitionDrawable在操作栏上执行一些颜色动画.
我正在尝试的代码非常简单,在onCreate期间,我将过渡drawable作为actionbar背景:
Drawable d = getResources().getDrawable(R.drawable.actionbar);
actionbarDrawable = new TransitionDrawable(new Drawable[] { d, d });
getActionBar().setBackgroundDrawable(actionbarDrawable);
Run Code Online (Sandbox Code Playgroud)
然后在事件上我替换了TransitionDrawable的第二个drawable并要求为它设置动画.
actionbarDrawable.setDrawableByLayerId(1, d);
actionbarDrawable.startTransition(666);
Run Code Online (Sandbox Code Playgroud)
我在我的活动上的RelativeLayout上尝试了相同的代码,它似乎工作正常,为什么ActionBar不想合作的任何想法以及如何使其工作?
谢谢.
android android-animation android-actionbar transitiondrawable