我試圖做一個簡單的幻燈片,淡出和淡入一些圖像沒有按鈕點擊。我發現了幾個例子來幫助我,但我無法讓第一張圖像淡入第二張圖像。到目前爲止,它只是淡出,就是這樣。下面我有我的代碼。使用ViewSwitcher的Android圖像幻燈片
fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="5000"
android:repeatCount="infinite"
/>
</set>
fade_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.1"
android:duration="5000"
android:repeatCount="infinite"
/>
</set>
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/switcher"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:inAnimation="@anim/fade_in"
android:outAnimation="@anim/fade_out" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="@drawable/image1" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="@drawable/image2" />
</ViewSwitcher>
MainClass.Activity
public class MainClass extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.next);
slideshow();
}
public void slideshow() {
ViewSwitcher switching = (ViewSwitcher)findViewById(R.id.switcher);
if (switching.getDisplayedChild() == 0) {
switching.showNext();
} else {
switching.showPrevious();
}
}
}