重複讓背景淡出、深入的動作:
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
public class BackgroundDemoActivity extends Activity {
private LinearLayout mLinearLayout;
private Animation alphaAnim;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mLinearLayout = (LinearLayout) findViewById(R.id.LinearLayout01);
alphaAnim = AnimationUtils.loadAnimation(this, R.anim.alpha);
mLinearLayout.setAnimation(alphaAnim);
}
}
************************************************
res/anim/alpha.xml:
<?xml version="1.0" encoding="utf-8"?>
<set android:shareInterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0"
android:toAlpha="0.6"
android:startOffset="0"
android:duration="5000"
android:repeatCount="infinite"
android:repeatMode="reverse"
/>
</set>
********************************
res/layout/main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/gradient_selector"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
*********************************
res/drawable/gradient_selector.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:endColor="#FF00FF00"
android:startColor="#FFFF0000"
android:type="linear" />
</shape>
</item>
</selector>
**********************************************
**********************************************
當然也可以換成:traslate
res/anim/translate.xml:
<?xml version="1.0" encoding="utf-8"?>
<set android:shareInterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="1"
android:toXScale="5"
android:fromYScale="1"
android:toYScale="5"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000"
android:repeatCount="infinite"
android:repeatMode="reverse"/>
<translate
android:fromXDelta="0"
android:toXDelta="20"
android:fromYDelta="0"
android:toYDelta="20"
android:startOffset="10"
android:duration="3000"
android:repeatCount="infinite"
android:repeatMode="reverse" />
</set>
***********************************************
***********************************************
或是
res/anim/rotate.xml:
<?xml version="1.0" encoding="utf-8"?>
<set android:shareInterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="3"
android:toXScale="3"
android:fromYScale="3"
android:toYScale="3"
android:pivotX="50%"
android:pivotY="50%"
android:duration="5000"
android:repeatCount="infinite"
android:repeatMode="restart"/>
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="10"
android:duration="5000"
android:repeatCount="infinite"
android:repeatMode="restart"/>
</set>
沒有留言:
張貼留言