我有 HorizontalScrollView,问题是添加视图后,这些视图之间有空格。这是一张图片:
这是该类的代码:
public class HomeFeatureLayout extends HorizontalScrollView {
public HomeFeatureLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public HomeFeatureLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public HomeFeatureLayout(Context context) {
super(context);
}
public void setFeatureItems() {
LinearLayout internalWrapper = new LinearLayout(getContext());
internalWrapper.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
internalWrapper.setOrientation(LinearLayout.HORIZONTAL);
addView(internalWrapper);
// this.mItems = items;
for (int i = 0; i < 10; i++) {
ImageView im = new ImageView(getContext());
im.setImageResource(R.drawable.aaaa);
im.setScaleType(ScaleType.CENTER_INSIDE);
im.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
internalWrapper.addView(im);
}
}
}
和 MainActivity:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
HomeFeatureLayout home = new HomeFeatureLayout(this);
home.setFeatureItems();
home.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
setContentView(home);
}
为什么每2个图像之间有空格?