How does android set margin in code and android code margin?

Source: Internet
Author: User

How does android set margin in code and android code margin?

1. First, let's see what the parent container of the component you want to set is. For example, I have a component in FrameLayout. For example, bottomLayout is:


Response. LayoutParams lp = new response. LayoutParams (ViewGroup. LayoutParams. WRAP_CONTENT, ViewGroup. LayoutParams. WRAP_CONTENT); lp. setMargins (0,100,); bottomLayout. setLayoutParams (lp );

Here, the meanings of the setMargins parameters are: Top left and bottom right.

Android interview questions Video Explanation


How does Android set margin in java code?

ImageView imageView = new ImageView (getContext ());
LinearLayout. LayoutParams lp = new LinearLayout. LayoutParams (LinearLayout. LayoutParams. WRAP_CONTENT, LinearLayout. LayoutParams. WRAP_CONTENT, 1); //, 1 is optional
Lp. setMargins (10, 20, 30, 40 );
ImageView. setLayoutParams (lp );

How does Android manually set the control's marginleft in Java code?

Follow these steps:

LinearLayout. LayoutParams abc = new LinearLayout. LayoutParams (.....);
Abc. setMargins (....);
ImageView. setLayoutParams (abc );

Related Article

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.