<shape
<!--圆角-->
<corners
android:radius="5dp"/>
<!-- 填充颜色-->
<solid
android:color="#ed0404"/>
<!-- 描边-->
<stroke
android:color="#0a25f4"
android:width="1dp"/>
<!-- 渐变-->
<gradient
android:startColor="#3c14ef"
android:endColor="#15cf2b"/>
/>
2.动画效果,在anim资源文件中需要自己去新建
(1)逐渐出现
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:duration="3000">
</alpha>
</set>
逐渐退出
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1"
android:toAlpha="0"
android:duration="3000">
</alpha>
</set>
在style方法中的调用
</style>
<style
name="pop">
<item
name="android:windowEnterAnimation">
@anim/pop_enter
</item>
<item
name="android:windowExitAnimation">
@anim/pop_exit
</item>
</style>
或者直接调用
overridePendingTransition(
R.anim.pop_enter,
R.anim.pop_exit);
(2)系统自带的左右平滑移动效果
overridePendingTransition(
android.R.anim.slide_in_left,
android.R.anim.slide_out_right
);
(3)补间动画
Animation animation = AnimationUtils.loadAnimation(getBaseContext(),
R.anim.anim1);
an1.startAnimation(animation);
(4)帧动画
an2.setBackgroundResource(R.drawable.drawable1);
animationDrawable
= (AnimationDrawable)
an2.getBackground();
animationDrawable.start();
其中在drawable里面添加相应的图片,如下
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="@mipmap/f1"
android:duration="200"
/>
<item
android:drawable="@mipmap/f2"
android:duration="200"
/>
<item
android:drawable="@mipmap/f3"
android:duration="200"
/>
<item
android:drawable="@mipmap/f4"
android:duration="200"
/>
<item
android:drawable="@mipmap/f5"
android:duration="200"/>
</animation-list>
(5)旋转360
ObjectAnimator oja=ObjectAnimator.ofFloat(an3,
"rotation",
0,
360);
oja.setDuration(3000);
//重复次数
oja.setRepeatCount(1);
//设置 插补器,设置动画效果
oja.setInterpolator(new
AccelerateDecelerateInterpolator());
oja.start();
(6)旋转0
ObjectAnimator oja=ObjectAnimator.ofFloat(an4,
"alpha",
0,
1);//透明alpha
oja.setDuration(3000);
oja.setRepeatCount(1);
//翻转
oja.setRepeatMode(ObjectAnimator.RESTART);
//设置 插补器,设置动画效果
oja.setInterpolator(new
LinearInterpolator());
oja.start();
(7)按压文字或者图片变换效果,在color或者drawable里面编写,如下
(1)按压文字,后面的表示默认颜色,还有state_focused,在布局文件中,color直接调用即可
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:color="#f40505"
android:state_pressed="true"/>
<item
android:color="#101010"/>
</selector>
(2)按压图片,还有state_focused,在布局文件中直接调drawable即可
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@mipmap/f8"
android:state_pressed="true"/>
<item
android:drawable="@mipmap/f10"
/>
</selector>