Android资源

设置全屏显示:

//去除标题栏
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//覆盖通知栏
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

 

还可以在项目配置文件里面添加:

   android:theme="@android:style/Theme.NoTitleBar" 

  android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"

 

音乐播放:

MediaPlayer mp;
// 创建一个mediaplayer对象
        mp = MediaPlayer
                .create(this, R.raw.kathrine_moholt_those_were_the_days);
        // 设置循环播放
        mp.setLooping(true);
//控制播放
if (mp.isPlaying()) {// 如果播放器在播放就停止,否则开始播放
                    mp.pause();
                } else {
                    mp.start();
                }
//在Activity销毁的时候记得也要把MediaPlayer资源释放
@Override
    protected void onDestroy() {
        super.onDestroy();
        if (mp.isPlaying()) {
            mp.stop();
            mp.release();
            mp = null;
        }
    }

帧动画:

1、写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/b1"
        android:duration="60"/>
    <item
        android:drawable="@drawable/b2"
        android:duration="60"/>
    <item
        android:drawable="@drawable/b3"
        
        android:duration="60"/>
    <item
        android:drawable="@drawable/b4"
        android:duration="60"/>

</animation-list>

 

2.XML文件创建动画对象

 

AnimationDrawable ad;
if (ad == null) {
                    // 加载AnimationDrawable
                    ad = (AnimationDrawable) TestActivity1.this.getResources()
                            .getDrawable(R.drawable.drawable_anim);
                    // 设置ImageButton的ImageDrawable;
                    ibt6.setImageDrawable(ad);
                    // 启动AnimationDrawable
                    ad.start();
                } else {
                    if (ad.isRunning()) {// 如果AnimationDrawable在运行就关闭,否则就启动
                        ad.stop();
                    } else {
                        ad.start();
                    }
                }

 

整型数组和字符串数组资源:

Arrays.xml文件里面

 

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string-array name="menu_title">
        <item>xml_arrays_里的str1</item>
        <item>xml_arrays_里的str2</item>
        <item>xml_arrays_里的str3</item>
        <item>xml_arrays_里的str4</item>
        <item>xml_arrays_里的str5</item>
    </string-array>

    <integer-array name="test_integer_array">
        <item>1</item>
        <item>111</item>
        <item>11111</item>
        <item>1111111</item>
        <item>111111111</item>
    </integer-array>

</resources>

 

// 用resource从xml中取出整形数组资源
				// 获得resource
				Resources resource = TestActivity1.this.getResources();
				// 取出数组资源
				int[] intArrayTemp = resource
						.getIntArray(R.array.test_integer_array);

 

图像旋转变形动画:

1、 XML文件

 

<?xml version="1.0" encoding="utf-8"?>
<!-- 属性interpolator:设置动画播放的速度(匀速,加速,减速等) -->
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator" >

    <!-- 缩放动画 -->
    <!-- duration:动画持续时间(毫秒) -->
    <!-- fromXScale:x方向起始尺寸(1.0表示正常尺寸) -->
    <!-- fromYScale:y方向起始尺寸(1.0表示正常尺寸) -->
    <!-- toXScale:x方向结束尺寸(1.0表示正常尺寸) -->
    <!-- toXScale:y方向结束尺寸(1.0表示正常尺寸) -->
    <!-- pivotX:缩放的中心位置 -->
    <!-- pivotY:缩放的中心位置 -->

    <scale
        android:duration="2000"
        android:fromXScale="0.1"
        android:fromYScale="0.1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1.0"
        android:toYScale="1.0" />

    <!-- 透明动画 -->
    <!-- fromAlpha:起始透明度 -->
    <!-- toAlpha:结束透明度 -->

    <alpha
        android:duration="2000"
        android:fromAlpha="0"
        android:toAlpha="1.0" />

    <!-- 旋转动画 -->
    <!-- fromDegrees:起始角度 -->
    <!-- toDegrees:结束角度 -->

    <rotate
        android:duration="2000"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="360" />

    <!-- 平移动画 -->

    <translate
        android:duration="2000"
        android:fromXDelta="-100"
        android:fromYDelta="-100"
        android:toXDelta="0"
        android:toYDelta="0" />

</set>

 

2、 从XML文件加载资源

 

// 从资源文件中得到一个Animation对象
                Animation anim = AnimationUtils.loadAnimation(
                        TestActivity1.this, R.anim.test_anim);
                // 给动画添加监听器
                anim.setAnimationListener(new AnimationListener() {

                    public void onAnimationStart(Animation animation) {
                    }

                    public void onAnimationRepeat(Animation animation) {
                    }

                    public void onAnimationEnd(Animation animation) {
                        // 动画播放完毕后让bt17重新可用
                        bt17.setEnabled(true);
                    }
// 给bt18上设置动画,并设置其可视
                bt18.setAnimation(anim);
                bt18.setVisibility(View.VISIBLE);

 

直接用XML文件来给界面控件添加不同的事件显示效果

 

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- 定义三个状态对应的颜色 1不可用状态-白色,2按下状态-绿色,3其他状态-黑色 -->
    <item android:state_enabled="false" android:color="@android:color/white"/>
    <item android:state_pressed="true" android:color="@color/green"/>
    <item android:color="@android:color/black"/>

</selector>

 

 

 

 

 

 

 

 

posted @ 2012-09-04 23:55  乌托邦.  阅读(1963)  评论(0编辑  收藏  举报