我拿画廊,而附加图像我拿 xml 中的列表视图。
显示 ListView 和图像。但无法滑动列表视图。
提前致谢。
public class MainActivity extends Activity {
Gallery gallery = null;
Activity appContext = this;
int[] images = { R.drawable.banana, R.drawable.apple, R.drawable.pineapple,
R.drawable.lemon, R.drawable.mango };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gallery = (Gallery) findViewById(R.id.gallery);
GalleryAdapter ga = new GalleryAdapter();
gallery.setAdapter(ga);
}
class GalleryAdapter extends BaseAdapter {
@Override
public int getCount() {
return 2;
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getView(int pos, View v, ViewGroup parent) {
v = LayoutInflater.from(appContext).inflate(R.layout.test1, null);
ImageView iv = (ImageView) v.findViewById(R.id.imageView1);
ListView lv = (ListView) v.findViewById(R.id.listView);
在这里,我附加了一个适配器来为 ListView 设置图像
ListAdapter la = new ListAdapter(appContext, images);
lv.setAdapter(la);
return v;
}
}
}
我的 ListAdapter 的另一个 getView 方法是
@Override
public View getView(int pos, View v, ViewGroup parent) {
v = LayoutInflater.from(appContext).inflate(R.layout.list_style, null);
ImageView iv = (ImageView) v.findViewById(R.id.iv_listStyle);
iv.setImageResource(images[pos]);
return v;
}