6

私は線形レイアウトを持っています

<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>

条件を設定すると

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

では、どのように設定するのlayout paramsですか?

4

5 に答える 5

12

パディングの場合:

LinearLayout mLayout = (LinearLayout)findViewById(R.id.layout_menu);
mLayout.setPadding(left, top, right, bottom);
于 2012-05-28T03:51:11.207 に答える
6
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);
于 2016-08-01T05:37:24.257 に答える
5

これがあなたに役立つことを願っています

LinearLayout.LayoutParams layout_param= new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.fill_parent,
                height * 2);
mLayout = (LinearLayout) findViewById(R.id.layout_menu);
mLayout.setLayoutParams(layout_param);
于 2012-05-28T03:48:47.287 に答える
0

線形レイアウトに余白を追加:-

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
     LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

layoutParams.setMargins(30, 20, 30, 0);
于 2016-08-01T05:41:40.370 に答える
0

あなたはこれをするべきではありません。最初に、デバイスに依存しないピクセル (dp) の代わりにピクセル (px) を使用しています。このようなことを行うと、特定のデバイス画面構成でのみ機能する UI が作成されます。アプリが画面密度に依存しないように、Android が画面密度の変化にどのように対処するかを学ぶ必要があります。ここから始める:

http://developer.android.com/guide/practices/screens_support.html

于 2012-05-28T03:52:43.207 に答える