我是android新手。我正在使用旋转木马,我想缩放选定的图像。这是我的carouseladapter类,我在getView()方法中接收所选图像的位置。关于这一点的任何帮助对我理解这个概念非常有帮助。
public class CarouselAdapter extends BaseAdapter {
private ArrayList<ImageView> mData = new ArrayList<ImageView>(0);
private Context mContext;
public CarouselAdapter(Context context) {
mContext = context;
}
public void setData(ArrayList<ImageView> data) {
mData = data;
}
@Override
public int getCount() {
return mData.size();
}
@Override
public Object getItem(int pos) {
return mData.get(pos);
}
@Override
public long getItemId(int pos) {
return pos;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView mImage= mData.get(position); //new ImageView(mContext);
Log.v("UITEST", "position: " + position);
// mImage.setImageResource(mData.size());
//mImage.setScaleType(ScaleType.CENTER_CROP);
//mImage.setPadding(5, 5, 5, 5);
//mImage.setBackgroundResource(R.drawableble.slider_bg);
return mImage;
}
}
答案 0 :(得分:0)
你可以使用它来缩放图像onItemSelectedListner
View lastSelectedView=null;
this.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3)
{
if(lastSelectedView!=null)
lastSelectedView.setLayoutParams(new Gallery.LayoutParams(200, 200));
arg1.setLayoutParams(new Gallery.LayoutParams(400, 250));
lastSelectedView=arg1;
}