1.int[] a={R.drawable.x1,R.drawable.x2,R.drawable.x3,R.drawable.x4};
2.版面安排
<?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="wrap_content"
android:gravity="center" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="產品展示"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="364dp" >
<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="match_parent"
android:src="@drawable/a13" />
</ImageSwitcher>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="上一張" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="下一張" />
</LinearLayout>
</LinearLayout>
3.public class ImageArray1 extends Activity implements ViewFactory
{
is1.setFactory(this);
. is1.setImageResource(img[0]);
.
.
public View makeView()
{
ImageView iv=new ImageView(this);
iv.setScaleType(ImageView.ScaleType.FIT_CENTER);
iv.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
return iv;
}
}
--------------------
package com.example.theoryproject1;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.*;
import android.widget.TableLayout.LayoutParams;
import android.widget.ViewSwitcher.ViewFactory;
public class Imageswitch2 extends Activity implements ViewFactory
{
private int[] img={R.drawable.a10,R.drawable.a11,R.drawable.a12,R.drawable.a13};
private ImageSwitcher is1=null;
private int po=0;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.imageswitch2);
is1=(ImageSwitcher)findViewById(R.id.imageSwitcher1);
is1.setFactory(this);
is1.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_in));
is1.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_out));
is1.setImageResource(img[0]);
Button bt1 = (Button)findViewById(R.id.button1);
Button bt2 = (Button)findViewById(R.id.button2);
bt1.setOnClickListener(mybtlistener5);
bt2.setOnClickListener(mybtlistener5);
}
Button.OnClickListener mybtlistener5 = new Button.OnClickListener()
{
@Override
public void onClick(View v) {
switch (v.getId())
{
case R.id.button1:
{
po--;
if (po<0)
{
po=img.length-1;
}
is1.setImageResource(img[po]);
break;
}
case R.id.button2:
{
po++;
if (po>img.length-1)
{
po=0;
}
is1.setImageResource(img[po]);
break;
}
}
}
};
@Override
public View makeView() {
// TODO Auto-generated method stub
ImageView iv =new ImageView(this);//動態建立ImageView
iv.setScaleType(ImageView.ScaleType.FIT_CENTER);
iv.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT,android.view.ViewGroup.LayoutParams.MATCH_PARENT));
return iv;
}
}
---------------------
<?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="wrap_content"
android:gravity="center" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="產品展示"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="364dp" >
<ImageSwitcher
android:id="@+id/imageSwitcher1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ImageSwitcher>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="上一張" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="下一張" />
</LinearLayout>
</LinearLayout>
-----------
package com.example.theoryproject1;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.TextView;
public class Animation1 extends Activity
{
private TextView tv=null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.animation1);
tv=(TextView)findViewById(R.id.textView1);
Button bt1 = (Button)findViewById(R.id.button1);
bt1.setOnClickListener(mybtlistener6);
}
Button.OnClickListener mybtlistener6 = new Button.OnClickListener()
{
@Override
public void onClick(View v) {
Animation an1= new RotateAnimation(0.0f,360.0f);
an1.setDuration(2000);
tv.startAnimation(an1);
}
};
}
----------------
<?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="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="啟動" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="北訊電腦"
android:textColor="#ff0000"
android:textSize="30sp" />
</LinearLayout>
</LinearLayout>
沒有留言:
張貼留言