[英]How to change the brightness of an image as its Ratingbar's rating is changed?
我是Android新手,希望我的问题很清楚。 我在适配器中的某个位置有一个图像和一个等级栏,并将它们添加到片段中。 我希望图像的亮度随着用户更改“等级”栏上的等级而改变,但不知道从哪里开始。 这是我实例化包含它们的布局的功能:
@Override
public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater = (LayoutInflater)container.getContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.rmd1_custom_imageslider_layout, null);
ImageView image=(ImageView) layout.findViewById(R.id.myimage);
image.setImageResource(CriteriaImages.get(position));
TextView text=(TextView) layout.findViewById(R.id.myImageViewText);
text.setText("Rate my "+CriteriaNames.get(position)+" today");
RatingBar rating = (RatingBar) layout.findViewById(R.id.ratingCategory);
rating.setId(position);
Button btn=(Button) layout.findViewById(R.id.done_button);
((ViewPager) container).addView(layout);
return layout;
}
您必须设置一个侦听器,即RatingBar.OnRatingBarChangeListener。
rating.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingBarChanged( .... ) {
//DO YOUR STUFF, like setting the alpha value of your image.
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.