在用viewpage做广告滚动的效果,根据照片的数量,每个照片生成一个圆点用来表示,当前照片滚动的位置,但是用LayoutParams 对象设置圆点的高和宽都正常,用setMargins设置圆点的间距却无效,请高手解答
private void initUI(Context context) {
LayoutInflater.from(context).inflate(R.layout.layout_slideshow, this,
true);
mLyTest= (ViewGroup) findViewById(R.id.ly_test);
int num = 0;
for (int imageID : this.getImagesResIds()) {
ImageView view = new ImageView(context);
view.setImageResource(imageID);
view.setScaleType(ScaleType.FIT_XY);
imageViewsList.add(view);
LayoutParams lp = new LayoutParams(63, 63,1);
lp.setMargins(500, 50, 500, 50);
ImageView viewImage = new ImageView(mContext);
viewImage.setId(imageID);
viewImage.setLayoutParams(lp);
viewImage.setPadding(50, 0, 50, 0);
if (num==0) {
viewImage.setBackgroundResource(R.drawable.dot_focused);
num++;
}else {
viewImage.setBackgroundResource(R.drawable.dot_normal);
}
mLyTest.addView(viewImage);
}
//
// dotViewsList.add(findViewById(R.id.v_dot1));
// dotViewsList.add(findViewById(R.id.v_dot2));
viewPager = (ViewPager) findViewById(R.id.viewPager);
viewPager.setFocusable(true);
viewPager.setAdapter(new MyPagerAdapter());
viewPager.setOnPageChangeListener(new MyPageChangeListener());
}
------解决思路----------------------
要看mLyTest这个变量具体是什么布局类型了,比如说是线性布局,然后把lp变量的类型改成LinearLayout.LayoutParams应该就可以了,我前段时间也遇到过这个问题