How to set android: layout_alignParentLeft attribute for image in code?

I want to get the same in the code as in this xml (this image is inside the relative layout):

<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:src="@drawable/logo"/> 

I know how to set the width and height of the layout, but I don't know how to set layout_alignParentLeft = "true".

Is it possible to do this in code?

+8
android layout
source share
2 answers
 RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); imageView.setLayoutParams(params); 
+32
source share

When adding an element to the code layout, you can provide LayoutParams . In this case, you want to use RelativeLayout.LayoutParms .

You can add a rule to the parameters to say that you want ALIGN_PARENT_LEFT.

0
source share

All Articles