我是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 . onratingbarchangellistener
rating.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingBarChanged( .... ) {
//DO YOUR STUFF, like setting the alpha value of your image.
}
}