我需要在滑块打开时减小滑动抽屉背景的不透明度,并在关闭时增加不透明度。
尝试在滑块打开/关闭时更改背景SlidingDrawer.OnDrawerOpenListener / SlidingDrawer.OnDrawerCloseListener,它不是我想要的。
非常感谢任何帮助。
答案 0 :(得分:2)
这是一个例子,试试这个:
使用TransitionDrawable
RelativeLayout layout = (RelativeLayout) findViewById(R.id.Layout);
layout.setBackgroundResource(R.drawable.translate);
TransitionDrawable transition = (TransitionDrawable) layout.getBackground();
transition.startTransition(5000);
此代码为您提供淡入淡出效果,如从黄色到白色(原始颜色)。
<强> translate.xml 强>
<?xml version="1.0" encoding="UTF-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The drawables used here can be solid colors, gradients, shapes, images, etc. -->
<item android:drawable="@drawable/new_state" />
<item android:drawable="@drawable/original_state" />
</transition>
<强> new_state.xml 强>
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFA7"/>
</shape>
<强> original_state.xml 强>
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
</shape>