我为几个视图的 alpha 通道设置了一个属性动画,但我认为它不能正常工作。本质上,我有 3 个TextView
导数,一个TextView
和两个Views
,我想最初隐藏,在数据进入时设置它们的数据,然后为它们设置动画。我用布局中的其他几个视图执行此操作,偶尔它们会遇到相同的问题,尽管它是非常罕见。大多数情况下,即使根据其 Logcat 输出的数据是有效的,简单的TextView
和其中之一也不会出现。它总是相同的两个视图,它们很少出现,但不是我能够找到的任何可预测的方式。布局文件的部分和所有动画代码如下。请注意,根据这个问题Views
TextView
,我已在布局中将可见性设置为不可见,并在开始动画之前将其设置为可见。
编辑
在有问题的视图上调用 `View.bringToFront() 没有明显的效果。此外,不执行动画而只是将视图的可见性从不可见更改为可见并不会显示它们。从布局中删除可见性更改代码和 android:visibility="invisible" 标记也不会使视图显示。
布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:qwerjk="http://schemas.android.com/apk/res/tenkiv.app"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingLeft="8dp"
android:paddingRight="8dp" >
<tenkiv.view.widget.MagicTextView
android:id="@+id/hourMinuteValueTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/secondValueTv"
android:lines="1"
android:textSize="77sp"
android:visibility="invisible"
qwerjk:strokeColor="@color/light_text_outline"
qwerjk:strokeJoinStyle="miter"
qwerjk:strokeWidth="1.8" />
<tenkiv.view.widget.MagicTextView
android:id="@+id/secondValueTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/hourMinuteValueTv"
android:layout_toLeftOf="@+id/amPmValueTv"
android:textSize="39sp"
android:visibility="invisible"
qwerjk:strokeColor="@color/light_text_outline"
qwerjk:strokeJoinStyle="round"
qwerjk:strokeWidth="1.3" />
<tenkiv.view.widget.MagicTextView
android:id="@+id/amPmValueTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/hourMinuteValueTv"
android:layout_alignParentRight="true"
android:textSize="31sp"
android:visibility="invisible"
qwerjk:strokeColor="@color/light_text_outline"
qwerjk:strokeJoinStyle="round"
qwerjk:strokeWidth="1.3" />
<tenkiv.view.widget.MagicTextView
android:id="@+id/dateValueTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/hourMinuteValueTv"
android:textSize="19sp"
android:visibility="invisible"
qwerjk:strokeColor="@color/light_text_outline"
qwerjk:strokeJoinStyle="round"
qwerjk:strokeWidth="0.9" />
<View
android:id="@+id/lineTimeConditionSepView"
android:layout_width="290dp"
android:layout_height="3dp"
android:layout_alignParentRight="true"
android:layout_below="@id/dateValueTv"
android:layout_marginTop="4dp"
android:background="@color/holo_text"
android:visibility="invisible" />
<View
android:id="@+id/lineTimeConditionSepViewOutline2"
android:layout_width="290dp"
android:layout_height="1dp"
android:layout_alignBottom="@id/lineTimeConditionSepView"
android:layout_alignLeft="@id/lineTimeConditionSepView"
android:layout_marginTop="0.5dp"
android:background="@color/location_area_dark_green"
android:visibility="invisible" />
---THE REST OF THE LAYOUT---
在我的片段中设置动画的方法
public void onUpdateClock(final String time, final String seconds, final String ampm, final String date) {
Activity activity = getActivity(); //Used to make sure we dont update the clock with the activity dead
if (activity != null) {
if (mHourMinuteValue == null) { //These are all used together so this should be safe
mHourMinuteValue = (MagicTextView) activity.findViewById(R.id.hourMinuteValueTv);
mSecondValue = (MagicTextView) activity.findViewById(R.id.secondValueTv);
mAmPmValue = (MagicTextView) activity.findViewById(R.id.amPmValueTv);
mDateValue = (TextView) activity.findViewById(R.id.dateValueTv);
mTimeConditionsLine = activity.findViewById(R.id.lineTimeConditionSepView);
mTimeConditionsOutline2 = activity.findViewById(R.id.lineTimeConditionSepViewOutline2);
mTimeInAnim = createAnimation(CLOCK_IN);
}
}
if (mHourMinuteValue == null) {
Log.e(TAG, "Clock text views were null!");
return;
}
uiHandler.post(new Runnable() {
public void run() {
mHourMinuteValue.setText(time);
mSecondValue.setText(seconds);
if (ampm != null) {
mAmPmValue.setText(ampm);
} else {
mAmPmValue.setText(ClockUICallbacks.EMPTY_AMPM);
}
mDateValue.setText(date);
mDateValue.bringToFront();
if (mFadeInClock) {
setClockVisibility(true);
mTimeInAnim.start();
mFadeInClock = false;
}
}
});
private void setClockVisibility(boolean visible) {
int flag;
if (visible) {
flag = View.VISIBLE;
} else {
flag = View.INVISIBLE;
}
mHourMinuteValue.setVisibility(flag);
mSecondValue.setVisibility(flag);
mAmPmValue.setVisibility(flag);
mDateValue.setVisibility(flag);
mTimeConditionsLine.setVisibility(flag);
mTimeConditionsOutline2.setVisibility(flag);
}
private AnimatorSet createAnimation(int type) {
AnimatorSet set = new AnimatorSet();
switch (type) {
case CLOCK_IN:
ValueAnimator hourMinInAnim = ObjectAnimator.ofFloat(mHourMinuteValue, "alpha", INVISIBLE, OPAQUE);
hourMinInAnim.setDuration(FADE_IN_DURATION);
ValueAnimator secondInAnim = ObjectAnimator.ofFloat(mSecondValue, "alpha", INVISIBLE, OPAQUE);
secondInAnim.setDuration(FADE_IN_DURATION);
ValueAnimator amPmInAnim = ObjectAnimator.ofFloat(mAmPmValue, "alpha", INVISIBLE, OPAQUE);
amPmInAnim.setDuration(FADE_IN_DURATION);
ValueAnimator dateInAnim = ObjectAnimator.ofFloat(mDateValue, "alpha", INVISIBLE, OPAQUE);
dateInAnim.setDuration(FADE_IN_DURATION);
ValueAnimator timeLine1InAnim = ObjectAnimator.ofFloat(mTimeConditionsLine, "alpha", INVISIBLE, OPAQUE);
timeLine1InAnim.setDuration(FADE_IN_DURATION);
ValueAnimator timeLine2InAnim = ObjectAnimator.ofFloat(mTimeConditionsOutline2, "alpha", INVISIBLE, OPAQUE);
timeLine2InAnim.setDuration(FADE_IN_DURATION);
set.playTogether(hourMinInAnim, secondInAnim, amPmInAnim, dateInAnim, timeLine1InAnim, timeLine2InAnim);
return set;
/*SOME OTHER ANIMATIONS*/
}
return null;
}
任何其他可能需要的信息请告诉我。
谢谢,贾里德