图片清晰度设置

//把圖片保存到数组里
private int imageViewId[] = {R.drawable.z1,R.drawable.z2,R.drawable.z3,R.drawable.z4,R.drawable.s1};
private ImageView iv_main_image;
private int currentIndex = 0;
private int transparent = 255;//图片的清晰度
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 首先要获取imageview控件
iv_main_image = findViewById(R.id.iv_main_image);
iv_main_image.setImageResource(imageViewId[currentIndex]);
}
public void last(View view){
if(currentIndex == 0){
Toast.makeText(this,”不能再上了,没人了”,Toast.LENGTH_SHORT).show();
}else {
currentIndex –;
iv_main_image.setImageResource(imageViewId[currentIndex]);
}

}
public void next(View view){

// 点击下一张按钮更改id
currentIndex++;
if(currentIndex >= imageViewId.length){
currentIndex = imageViewId.length -1;
Toast.makeText(this,”目前已经是最后一张了,充钱查看更多”,Toast.LENGTH_SHORT).show();
}else {
// 将更新后的图片id设置会imageview控件
iv_main_image.setImageResource(imageViewId[currentIndex]);
}

}
public void add(View view){
    if(transparent<= 235){
        transparent = transparent +20;
        //                然后再将改变后的值设置会imageview控件
        iv_main_image.setImageAlpha(transparent);
    }else {
        Toast.makeText(this,"目前已经是高清了",Toast.LENGTH_SHORT).show();
    }
}
public void del(View view){

// 首先要获取imageview控件
// 默认透明度是255,也就是完全不透的,点击透明按钮,我们要控制透明度的值减小
// System.out.println(“##########################################”+(transparent–));
// System.out.println(“##########################################”+(–transparent));

    if(transparent>=20){
        transparent = transparent -20;
        //                然后再将改变后的值设置会imageview控件
        iv_main_image.setImageAlpha(transparent);
    }else {
        Toast.makeText(this,"再透明就什么都看不见了",Toast.LENGTH_SHORT).show();
    }
    ;

}

//xml







<!--<LinearLayout-->
    <!--android:layout_width="match_parent"-->
    <!--android:layout_height="wrap_content">-->

    <!--<Button-->
        <!--android:layout_width="wrap_content"-->
        <!--android:layout_height="wrap_content"-->
        <!--android:onClick="last"-->
        <!--android:text="&lt;"/>-->
    <!--<Button-->
        <!--android:layout_width="wrap_content"-->
        <!--android:text="+"-->
        <!--android:onClick="add"-->
        <!--android:layout_height="wrap_content" />-->
    <!--<Button-->
        <!--android:layout_width="wrap_content"-->
        <!--android:text="-"-->
        <!--android:onClick="del"-->
        <!--android:layout_height="wrap_content" />-->
    <!--<Button-->
        <!--android:layout_width="wrap_content"-->
        <!--android:text="&gt;"-->
        <!--android:onClick="next"-->
        <!--android:layout_height="wrap_content" />-->
<!--</LinearLayout>-->

<!--<ImageView-->
    <!--android:layout_width="300dp"-->
    <!--android:layout_height="300dp"-->
    <!--android:id="@+id/iv_main_image"-->
    <!--/>-->

<!--<ImageView-->
    <!--android:layout_width="100dp"-->
    <!--android:id="@+id/iv_main_imageNew"-->
    <!--android:layout_height="100dp"-->
    <!--/>-->
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值