1:UI设计方面
设置某张图片的颜色过滤
private static final ColorFilter BLACK_CF = new LightingColorFilter(Color.BLUE, Color.BLACK);
public static Drawable buildDrawable(Context ctx, int drawableId) {
Drawable d = ctx.getResources().getDrawable(drawableId);
d.setColorFilter(BLACK_CF);
return d;
}
给某个View 设置动画
java 代码
private AnimationDrawable loadingAnimation;
private View loginLoading;
loginLoading = (View)findViewById(R.id.login_loading);
loadingAnimation = (AnimationDrawable)loginLoading.getBackground();
loadingAnimation.start();
xml中设置
<View
android:id="@+id/login_loading"
android:layout_width="135.0dip"
android:layout_height="135.0dip"
android:layout_gravity="center"
android:background="@anim/login_loading" />
anim (多层动画,也可设置单层动画)
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item android:duration="500">
<layer-list>
<item android:drawable="@drawable/login_loading_00"/>
<item android:drawable="@drawable/login_loading_10"/>
</layer-list>
</item>
<item android:duration="500">
<layer-list>
<item android:drawable="@drawable/login_loading_01"/>
<item android:drawable="@drawable/login_loading_11"/>
</layer-list>
</item>
</animation-list>
ViewSwitcher的使用
xml中
<ViewSwitcher
android:id="@+id/logindialog_view_switcher"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/login_btn_login"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:background="@drawable/login_btn_selector"
android:text="@string/login_dialog_login"
android:textSize="@dimen/text_size_20" />
<View
android:id="@+id/login_loading"
android:layout_width="135.0dip"
android:layout_height="135.0dip"
android:layout_gravity="center"
android:background="@anim/login_loading" />
</ViewSwitcher>
java中:
private Button btn_login;
private View loginLoading;
btn_login = (Button)findViewById(R.id.login_btn_login);
loginLoading = (View)findViewById(R.id.login_loading);
btn_login.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mViewSwitcher.showNext();
}
});
效果:点击button后 view出现 可以给view设置一个动画 (一次性)