我正在尝试从'方法更新 a TextView
(让我们称之为)。问题是,在我调用之后,移动 SwitchCompat 拇指按钮的动画会中断,拇指按钮会跳到另一边。这是示例:name
SwitchCompat
OnCheckedChanged()
name.setText()
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
name.setText("Some name");
}
我也尝试使用Handler
发布我的更新,结果发现如果我在动画完成之前发布,它仍然会被中断。例如,如果动画拍摄1000 ms
并且我postDelayed()
以 的延迟调用500 ms
,则拇指按钮会平滑地移动到 的中间,SwitchCompat
然后只是跳跃。代码:
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
name.setText("Some name");
}
}, 500);
两个视图都是单个布局的一部分(代表一个ListView
项目):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:addStatesFromChildren="true"
android:descendantFocusability="blocksDescendants"
android:paddingBottom="5dp">
<TableLayout
android:id="@+id/mainPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="0">
<TableRow>
<android.support.v7.widget.SwitchCompat
android:id="@+id/isAlarmOn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"/>
</TableRow>
</TableLayout>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/mainPanel" />
</RelativeLayout>
那么如何在TextView
不破坏动画的情况下改变它呢?