ImageSwitcher:
package com.example.theoryproject1;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class Imageswitch1 extends Activity
{
private ImageSwitcher is1=null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.imageswitch1);
is1=(ImageSwitcher)findViewById(R.id.imageSwitcher1);
Button bt1=(Button)findViewById(R.id.button1);
Button bt2=(Button)findViewById(R.id.button2);
bt1.setOnClickListener(mybtlistener3);
bt2.setOnClickListener(mybtlistener3);
}
Button.OnClickListener mybtlistener3 = new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
switch (v.getId())
{
case R.id.button1:
{
is1.showPrevious();
break;
}
case R.id.button2:
{
is1.showNext();
break;
}
}
}
};
}
-----------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="412dp" >
<ImageSwitcher
android:id="@+id/imageSwitcher1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/a10" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/a11" />
</ImageSwitcher>
</LinearLayout>
----------------------
沒有留言:
張貼留言