Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set android:layout_alignParentLeft attribute to imageview in code?

Tags:

android

layout

I want to achieve the same thing in code as it is in this xml (this imageview is inside 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 layout width and height, but don't know how to set layout_alignParentLeft="true".

Is it possbile to do this in code?

like image 851
DixieFlatline Avatar asked Jan 27 '11 17:01

DixieFlatline


1 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);
like image 187
Cristian Avatar answered Sep 20 '22 10:09

Cristian