imageView = new ImageView(NavigationActivity.this);
imageView.setLayoutParams(new LayoutParams(12,12));
imageView.setPadding(20, 0, 20, 0);
设置ImageView的setPadding(20, 0, 20, 0); 不起作用
改为
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(12, 12);
params.setMargins(0, 0,13, 0);
imageView = new ImageView(NavigationActivity.this);
imageView.setLayoutParams(params);
//////////////////////////////////////////////////////////////////////////////////////////////
private void init() {
// LinearLayout.LayoutParams用于控制两个点之间的距离
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(20,20);
params.setMargins(20, 0, 20, 0);
for (int i = 0; i < pageViews.size(); i++) {
imageView = new ImageView(InitStartActivity.this);
imageViews = imageView;
if (i == 0) {
//默认选中第一张图片
imageViews.setBackgroundResource(R.drawable.page_indicator_focused);
} else {
imageViews.setBackgroundResource(R.drawable.page_indicator);
}
// 指明某个ImageView需要左右隔开 20xp setPadding不起作用
group.addView(imageViews,params);
}
setContentView(main);
viewPager.setAdapter(new GuidePageAdapter());
viewPager.setOnPageChangeListener(new GuidePageChangeListener());
}