由于web不符合当前课程所需要的方向,所以将web项目的编程改为Android项目的开发,从界面设计和界面的跳转开始学习设计。
本周计划Android的学习开发路线,分配成员任务。
package com.example.test04;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;
public class MainActivity extends AppCompatActivity implements View.OnClickListener, ViewSwitcher.ViewFactory
{
private ImageSwitcher is_1;
private Button btn_next;
private Button btn_prevIoUs;
private int image[]={R.drawable.a1,R.drawable.a2,R.drawable.a3,R.drawable.a4};
private int imageIndex = 0;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
is_1 =
findViewById(R.id.is_1);
btn_next =
findViewById(R.id.btn_next);
btn_prevIoUs =
findViewById(R.id.btn_prebIoUs);
init();
btn_prevIoUs.setonClickListener(this);
btn_next.setonClickListener(this);
}
@Override
public View makeView(){
ImageView imageView = new ImageView(this);
return imageView;
}
private void init(){
is_1.setFactory(this);
is_1.setimageResource(image[imageIndex]);
}
@Override
public void onClick(View v) {
if (v.getId() ==
R.id.btn_next){
imageIndex++;
if (imageIndex>3){
imageIndex=0;
};
is_1.setInAnimation(this,R.anim.leftin);
is_1.setoutAnimation(this,R.anim.rightout);
}else if (v.getId() ==
R.id.btn_prebIoUs){
imageIndex--;
if (imageIndex<0){
imageIndex=image.length-1;
};
is_1.setInAnimation(this,R.anim.rightin);
is_1.setoutAnimation(this,R.anim.leftout);
}
is_1.setimageResource(image[imageIndex]);
}
}