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 );