Setmargins does not work

Source: Internet
Author: User
Problem description
When you use viewpage for advertising and scrolling, a dot is generated for each photo based on the number of photos. The current photo is rolling, but the height and width of the dot are set to normal with the layoutparams object, setting the dot spacing with setmargins is invalid.
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());}
Solution 1
It depends on the specific layout type of the mlytest variable, for example, linear layout, and then change the LP variable type to linearlayout. layoutparams. I have encountered this problem some time ago.

Setmargins does not work

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.