我有一個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