Android ImageView控件和SeekBar的问题

l2190215487 2016-07-31 04:03:43
通过SeekBar控件改变图片的透明度,并用Toast随时图片的透明度,然后发现不管怎么调SeekBar,图片的透明度都始终是1.0,这让我很费解,大神们指导下。。
这是java代码:
package com.example.application.seekbar;

import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

Toast toast;
SeekBar seekBar;
ImageView imageView;
Float f;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

seekBar = (SeekBar)findViewById(R.id.seekbar1);
imageView = (ImageView)findViewById(R.id.imageview1);
f = imageView.getAlpha();
toast=Toast.makeText(getApplicationContext(), f.toString(), Toast.LENGTH_SHORT);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
imageView.setImageAlpha(progress);
f = imageView.getAlpha();
toast=Toast.makeText(getApplicationContext(), f.toString(), Toast.LENGTH_SHORT);
toast.show();
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});
}
}


这是xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.application.seekbar.MainActivity">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageview1"
android:src="@drawable/hello3"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/seekbar1"
android:max="200"
android:progress="100"/>
</LinearLayout>
...全文
179 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
l2190215487 2016-08-01
  • 打赏
  • 举报
回复
引用 2 楼 xjz729827161 的回复:
f = imageView.getAlpha(); 你代码里面获取的是imageView这个控件的透明值啊,而你设置的是图片的透明度
了解了,非常感谢
xjz729827161 2016-07-31
  • 打赏
  • 举报
回复
f = imageView.getAlpha(); 你代码里面获取的是imageView这个控件的透明值啊,而你设置的是图片的透明度
l2190215487 2016-07-31
  • 打赏
  • 举报
回复
补充一句,调节SeekBar确实能改变图片的透明度,但是ImageView.getImageAlpha()得到的值始终不变。

80,353

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧