由于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]);
}
}
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/273148.html