Andrid studio图片的切换,分辨率的调整

1.xml资源




   

       

2.代码

package com.example.android06;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private int ImgViewId[]={R.drawable.a1,R.drawable.a2,R.drawable.a3,R.drawable.a4}; //图片数组
    private  ImageView iv_main_image;
    private  int currentIndex=0;
    private int ten=255;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv_main_image= findViewById(R.id.iv_main_image);
        iv_main_image.setImageResource(ImgViewId[currentIndex]);
    }

    //上一张
    public void last(View view) {
        currentIndex--;
        if(currentIndex>0){
            iv_main_image.setImageResource(ImgViewId[currentIndex]);
        }
        else{
            Toast.makeText(this, "没有上一张了", Toast.LENGTH_SHORT).show();
        }

    }

    //下一张
    public void next(View view) {
        currentIndex++;
        if(currentIndex=255){
            Toast.makeText(this, "已经是最清楚的了", Toast.LENGTH_SHORT).show();
        }
        else{
            iv_main_image.setImageAlpha(ten);
        }
    }

    //减少
    public void deleteu(View view) {

    ten=ten-10;
    if(ten>0){
        iv_main_image.setImageAlpha(ten);
    }
    else{
        Toast.makeText(this, "再减少就看不见了", Toast.LENGTH_SHORT).show();
    }

    }
}

你可能感兴趣的:(Andrid studio图片的切换,分辨率的调整)