Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android negative margin does not work

Tags:

android

I have encountered a problem when i try to give a negative left margin to a LinearLayout.
The negative margin does not appear.
Here is my code

HorizontalScrollView hview = new HorizontalScrollView(context); //  HorizontalScrollView is the outer view   
RelativeLayout.LayoutParams hs_lot_params = new RelativeLayout.LayoutParams(164, 164);
hs_lot_params.setMargins(100, 100, 0, 0); // set the positions

ImageView image = new ImageView(context);
image.setBackgroundResource(R.drawable.leder);
LinearLayout.LayoutParams img_lot_params = new LinearLayout.LayoutParams(164, 164);
img_lot_params.setMargins(0, 0, 0, 0);

LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(164, 164);
layoutParams.setMargins(-132, 0, 0, 0);
ll.addView(image, img_lot_params);
hview.addView(ll, layoutParams);

Note: my plan is to scroll the image from left to right.
First, the left part of the image is hidden and can scroll to right to see the full image

like image 488
Jis Jose Avatar asked Aug 17 '13 12:08

Jis Jose


1 Answers

 ViewGroup.MarginLayoutParams params =
 (ViewGroup.MarginLayoutParams)view.getLayoutParams(); params.topMargin = -100;
like image 76
Rohit Suthar Avatar answered Sep 24 '22 16:09

Rohit Suthar