java - Android - Set Layout_Gravity programmatically for LinearLayout -


i've got following problem: implemented horizontalscrollview contains in 1 case linearlayout , imageview. in case image 50% of screen width. want center it. unfortunately way found center is, use layout_gravity="center" on linearlayout.

here's xml:

<horizontalscrollview             android:layout_gravity="center"             android:layout_width="fill_parent"             android:layout_height="wrap_content">          <linearlayout                 android:orientation="horizontal"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content">          <imageview                                     android:src="@drawable/myimg"                 android:layout_width="wrap_content"                 android:adjustviewbounds="true"                 android:layout_height="150dp"/>          </linearlayout>      </horizontalscrollview> 

but need set layout_gravity programmatically. has idea how can achieve or knows different way? things found via google not working me this post.

thanks!

do somethings :

   layoutparams lp = new layoutparams();    lp.gravity= gravity.center_horizontal;     myimg.setlayoutparams(lp); 

update : way :

linearlayout.layoutparams params = new linearlayout.layoutparams(                 layoutparams.wrap_content, layoutparams.wrap_content);             params.weight = 1.0f;             params.gravity = gravity.center;              imageview.setlayoutparams(params); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -