我有一个HorizontalScrollView,它包含一个水平LinearLayout。现在,我将同样大的ImageView添加到LinearLayout中,以便我可以在ImageView之间滚动。 ImageViews应该并排放置,并且两者之间没有空间,但是每个图像的两侧都会产生巨大的空间(我认为它是图像宽度的一半)。如何摆脱LinearLayout中Views之间的空间
以下是我如何做到这一点,希望有人对我有帮助。
public class SnapGallery extends HorizontalScrollView {
private ArrayList<Bitmap> items = null;
protected Context context = null; //Context of the activity
protected LinearLayout wrapper = null; //This serves as a container for the images in the SnapGallery.
//Constructor
public SnapGallery(Context context) {
super(context);
this.context = context;
items = new ArrayList<Bitmap>();
this.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
wrapper = new LinearLayout(context);
wrapper.setOrientation(LinearLayout.HORIZONTAL);
wrapper.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
wrapper.setPadding(0, 0, 0, 0);
wrapper.setGravity(Gravity.LEFT);
this.addView(wrapper);
items = getTestBitmaps();
for (Bitmap b : items) {
ImageView curr = createViewFromBitmap(b);
wrapper.addView(curr, new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f));
}
}
public ImageView createViewFromBitmap (Bitmap bitmap) {
ImageView view = new ImageView(context);
view.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
view.setPadding(0, 0, 0, 0);
view.setImageBitmap(bitmap);
return view;
}
}
在此先感谢!
你检查/设置边距为0以及填充? – Kerry