我有这个XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="45dp"
android:layout_height="32dp"
android:id="@+id/switch_bg"
android:padding="0dp"
android:background= "@drawable/switch_bg_off" >
<RelativeLayout
android:id="@+id/switch_handle"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@drawable/switch_handle"
android:padding="0dp" >
<ImageView
android:id="@+id/switch_v"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_centerInParent="true"
android:src="@drawable/switch_v" />
</RelativeLayout>
</RelativeLayout>
我在用户点击
上调用此方法然后隐藏背景上方的所有视图。
private void bgTransition(SwitchModes mode) {
AlphaAnimation alpha = new AlphaAnimation(1, (float) 0.5);
alpha.setDuration(ALPHA_DURATION);
mSwitchBg.startAnimation(alpha);
switch (mode) {
case CHECKED: {
// mBgTransition.reverseTransition(BG_TRANSITION_TIME);
mSwitchBg.setBackgroundResource(R.drawable.switch_bg_off);
break;
}
case UNCHECKED: {
// mBgTransition.startTransition(BG_TRANSITION_TIME);
mSwitchBg.setBackgroundResource(R.drawable.switch_bg_on);
break;
}
}
alpha = new AlphaAnimation((float) 0.5, 1);
alpha.setDuration(ALPHA_DURATION);
mSwitchBg.startAnimation(alpha);
}
如何解决这个问题?