java Android ObjectAnimator未在AlertDialog中工作<SOLVED>
我试图在AlertDialog中模拟车库门开启器,并希望在按下按钮时模拟对话框内LED的闪烁
为此,我创建了一个圆形LED,并按如下方式加载:
`final View mCircle = findViewById(R.id.circleLED);` <----- false
正确加载修复了我的问题:
final View mCircle = dialogsView.findViewById(R.id.circleLED);
在布局中。xml中,循环定义为:
<View
安卓:id="@+id/circleLED"
安卓:layout_width="24dp"
安卓:layout_height="16dp"
安卓:layout_centerInParent="true"
安卓:layout_marginStart="184dp"
安卓:layout_marginLeft="184dp"
安卓:layout_marginTop="80dp"
安卓:background="@drawable/solid_circle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
可绘制的图形定义为实心圆。xml格式如下:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:shape="oval">
<solid 安卓:color="@color/colorAccent"/>
</shape>
然后我设置了ObjectAnimator:
`final ObjectAnimator objAnimator = ObjectAnimator.ofFloat(mCircle, "alpha",0f, 1f);
objAnimator.setDuration(100);
objAnimator.setEvaluator(new TypeEvaluator<Float>()
{
@Override
public Float evaluate(float fraction, Float startValue, Float endValue)
{
return (startValue + (endValue - startValue) * fraction);
}
});
objAnimator.setRepeatMode(ValueAnimator.REVERSE);
objAnimator.setRepeatCount(Animation.INFINITE);
objAnimator.start();`
在活动中使用完全相同的代码时,圆圈会像符咒一样闪烁。 但在警报对话框中使用此代码时,根本不会闪烁任何内容
我不想将活动用于远程模拟。我希望它在一个警报对话框中。 我如何解决这个问题
共 (0) 个答案