资源文件的总结-----------(1)

1.使用资源文件为了国际化,不同的语言在UI展示不同的效果


2.Value的String中占位符的使用-----这样可以避免使用两个textView
 <!-- 应用详情 -->
    <string name="app_detail_info_downloadnum">下载: %1$s</string>
    <string name="app_detail_info_version">版本: %1$s</string>
    <string name="app_detail_info_time">时间: %1$s</string>
    <string name="app_detail_info_size">大小: %1$s</string>
$s  代表的是String类型的占位
$d   代表的是数字类型不管是float还是int
%1   代表有一个占位符


如此就能动态的添加东西
context.getResource().getString(R.string.xxx,String类型)


3.实际上资源文件使用的是反射技术,在drawable文件中的xml文件都是会被变成对应View类的
------------3.1
选择器selector----

相关属性:

android:state_selected是选中
android:state_focused
是获得焦点
android:state_pressed
是点击
android:state_enabled
是设置是否响应事件,指所有事件

<?xml version="1.0" encoding="utf-8" ?>   
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<!--
 默认时的背景图片-->  
  <item android:drawable="@drawable/pic1" />  
  
<!--
 没有焦点时的背景图片 -->  
  <item android:state_window_focused="false"   
        android:drawable="@drawable/pic1" />   
<!--
 非触摸模式下获得焦点并单击时的背景图片 -->  
  <item android:state_focused="true" 
android:state_pressed="true"   android:drawable= "@drawable/pic2" /> 

<!-- 触摸模式下单击时的背景图片-->  

<item android:state_focused="false" android:state_pressed="true"   android:drawable="@drawable/pic3" />  

<!--选中时的图片背景-->  

  <item android:state_selected="true"   android:drawable="@drawable/pic4" />   

<!--获得焦点时的图片背景-->  

  <item android:state_focused="true"   android:drawable="@drawable/pic5" />   
</selector>

注意红色位置,我有呀将默认的图片放在第一个位置,这样有事可以有时不可以

可能和底部有关系,建议一般放置在最后面



4.在android studio中

代替了原来的drawable实际上除了使用更麻烦之外没什么好处

不过谷歌介绍是对GPU更好


5.帧动画的格式

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"  android:oneshot="false"   >
android:oneshot表示是否重复播放,true表示播放一次,false表示重复播放
android:duration="100" 表示播放时间间隔
girl_list.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false" >
    <item
        android:drawable="@drawable/girl_1"
        android:duration="100"/>
    <item
        android:drawable="@drawable/girl_2"
        android:duration="100"/>
    <item
        android:drawable="@drawable/girl_3"
        android:duration="100"/>
    <item
        android:drawable="@drawable/girl_4"
        android:duration="100"/>
    <item
        android:drawable="@drawable/girl_5"
        android:duration="100"/>
    <item
        android:drawable="@drawable/girl_6"
        android:duration="100"/>
    <item
        android:drawable="@drawable/girl_7"
        android:duration="200"/>
    <item
        android:drawable="@drawable/girl_8"
        android:duration="100"/>
    <item
        android:drawable="@drawable/girl_9"
        android:duration="100"/>
    <item
        android:drawable="@drawable/girl_10"
        android:duration="100"/>
    <item
        android:drawable="@drawable/girl_11"
        android:duration="100"/>
</animation-list>
使用------------
   private AnimationDrawable rocketAnimation;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ImageView rocketImage = (ImageView) findViewById(R.id.iv);
        rocketImage.setBackgroundResource(R.drawable.girl_list);// 1、和drawable中的xml文件名一样
        // 2、getBackground()需要一定的时间,低级的sdk如果和start()放在一起,可能播放不出来
        rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
    }
    /**
     * 播放帧动画
     * @param view
     */
    public void play(View view) {
        rocketAnimation.start();
    }
5.补间动画
Tween Animation动画:
本例要实现对ImageView对象进行渐变尺寸缩放动画效果
1> 在项目的res目录下创建文件夹anim,然后在anim文件夹下面定义动画XML文件,文件名称可以自定义,如:scale.xml,内容如下:
<?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator" 
        android:fromXScale="0.0" 
        android:fromYScale="0.0"  
        android:toXScale="5" 
        android:toYScale="5" 
        android:pivotX="50%" 
        android:pivotY="50%" 
        android:fillAfter="false" 
        android:duration="5000"
        /> 
</set>
动画的进度使用interpolator控制,android提供了几个Interpolator 子类,实现了不同的速度曲线,如LinearInterpolator实现了匀速效果、Accelerateinterpolator实现了加速效果、DecelerateInterpolator实现了减速效果等。还可以定义自己的Interpolator子类,实现抛物线、自由落体等物理效果。
fromXScale(浮点型) 属性为动画起始时X坐标上的缩放尺寸 
fromYScale(浮点型) 属性为动画起始时Y坐标上的缩放尺寸
toXScale(浮点型)   属性为动画结束时X坐标上的缩放尺寸
toYScale(浮点型)   属性为动画结束时Y坐标上的缩放尺寸
说明: 以上四种属性值 
0.0表示收缩到没有 
1.0表示正常无缩放
值小于1.0表示收缩 
值大于1.0表示放大
pivotX(浮点型)     属性为动画相对于物件的X坐标的开始位置 
pivotY(浮点型)     属性为动画相对于物件的Y坐标的开始位置 
说明: 
以上两个属性值 从0%-100%中取值
50%为物件的X或Y方向坐标上的中点位置
duration(长整型)属性为动画持续时间 。说明:   时间以毫秒为单位
fillAfter(布尔型)属性当设置为true,该动画转化在动画结束后被应用
使用:
ImageView imageView = (ImageView)this.findViewById(R.id.imageView);
        //加载动画XML文件,生成动画指令
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.scale);
        //开始执行动画
        imageView.startAnimation(animation);



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值