我在扩展的LinearLayout上实现了OnCenterProximityListener,如果我将WearableListView抛弃,当它停止时,在触发onCenterPosition和onNonCenterPosition之前会有一个短暂的延迟。
getcheckupID()
以下是项目的XML
public class HourListView extends LinearLayout
implements WearableListView.OnCenterProximityListener {
public HourListView(Context context) {
this(context, null);
}
public HourListView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public HourListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
private TextView mHr;
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mHr = (TextView) findViewById(R.id.hr);
mHr.animate().setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
mHr.setTag(1);
}
@Override
public void onAnimationEnd(Animator animation) {
mHr.setTag(0);
}
@Override
public void onAnimationCancel(Animator animation) {}
@Override
public void onAnimationRepeat(Animator animation) {}
});
}
@Override
public void onCenterPosition(boolean animate) {
if (mHr.getTag() == null || (int) mHr.getTag() == 0) {
mHr.setAlpha(1f);
mHr.setTextColor(Color.argb(255, 49, 133, 255));
}
if (mHr.getTag() == null) {
mHr.animate().setDuration(0).setStartDelay(0).scaleX(1.6f).scaleY(1.6f);
} else if ((int) mHr.getTag() == 0) {
mHr.animate().setDuration(200).setStartDelay(0).scaleX(1.6f).scaleY(1.6f);
}
}
@Override
public void onNonCenterPosition(boolean animate) {
if(mHr.getTag() == null || (int) mHr.getTag() == 0) {
mHr.setAlpha(.4f);
mHr.setTextColor(Color.argb(255, 0, 0, 0));
}
if (mHr.getTag() == null) {
mHr.animate().setDuration(0).setStartDelay(0).scaleX(1f).scaleY(1f);
} else if ((int) mHr.getTag() == 0) {
mHr.animate().setDuration(200).setStartDelay(0).scaleX(1f).scaleY(1f);
}
}
}
这是WearListView的XML
<?xml version="1.0" encoding="utf-8"?>
<com.daford.wearalarmlistview.HourListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/hr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1"
android:gravity="center"
android:textSize="40dp"
android:layout_centerInParent="true"/>
</com.daford.wearalarmlistview.HourListView>
我正在使用AnimatorListener来设置和清除TextView中的Tag,因为看起来OnCenterProximityListener被同一个TextView多次调用。我在没有AnimatorListener的情况下尝试过它,它仍然是相同的。