Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set padding or margin to linear layout?

I have a linear layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_menu"
android:layout_width="fill_parent"
android:layout_height="70px"
android:layout_alignParentBottom="true"
android:background="@drawable/footer_bar"
android:gravity="center" >
</LinearLayout>

When i set condition

if (constant.getscreenresolution() >= 800) {
    //i want to make it height * 2
}

So how to set the layout params?

like image 925
Alan Lai Avatar asked May 28 '12 03:05

Alan Lai


3 Answers

For padding:

LinearLayout mLayout = (LinearLayout)findViewById(R.id.layout_menu);
mLayout.setPadding(left, top, right, bottom);
like image 108
Hanon Avatar answered Sep 24 '22 11:09

Hanon


LinearLayout mLayout = (LinearLayout)v.findViewById(R.id.ll_winfowindo);
int left= (int) activity.getResources().getDimension(R.dimen._18sdp);
int top=(int) activity.getResources().getDimension(R.dimen._22sdp);
int right=(int) activity.getResources().getDimension(R.dimen._18sdp);
int bottom=(int) activity.getResources().getDimension(R.dimen._34sdp);
mLayout.setPadding(left, top, right, bottom);
like image 42
Maulik Dadhaniya Avatar answered Sep 24 '22 11:09

Maulik Dadhaniya


hope this helps you

LinearLayout.LayoutParams layout_param= new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.fill_parent,
                height * 2);
mLayout = (LinearLayout) findViewById(R.id.layout_menu);
mLayout.setLayoutParams(layout_param);
like image 39
MichaelP Avatar answered Sep 23 '22 11:09

MichaelP