Android layout 如何以编程方式更改框架布局高度和宽度?

Android layout 如何以编程方式更改框架布局高度和宽度?,android-layout,Android Layout,我是android新手 我面临的一个问题是,我正在将框架布局添加到我的应用程序中,代码是 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" androi

我是android新手

我面临的一个问题是,我正在将框架布局添加到我的应用程序中,代码是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <FrameLayout android:id="@+id/frameLayout1">
        <LinearLayout 
        android:layout_height="wrap_content" 
        android:id="@+id/linearLayout1" 
        android:layout_width="fill_parent">
        </LinearLayout>
    </FrameLayout>
</LinearLayout>

我的问题是我想改变不同屏幕方向的框架布局高度

示例代码是

    wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);

            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

            Log.v("height","height"+wm.getDefaultDisplay().getHeight());

            if(wm.getDefaultDisplay().getHeight() <= 427)
             {
                 Log.v("height","111");


((FrameLayout)findViewById(R.id.frameLayout1)).setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
         }
        else
        {
            ((FrameLayout)findViewById(R.id.frameLayout1)).setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
        }
wm=(WindowManager)getSystemService(Context.WINDOW\u服务);
getWindow().addFlags(WindowManager.LayoutParams.FLAG\u保持屏幕打开);
Log.v(“height”、“height”+wm.getDefaultDisplay().getHeight());

if(wm.getDefaultDisplay().getHeight()一种方法是构建自定义视图并覆盖onLayout和onMeasure函数。在onLayout函数中,可以覆盖宽度和高度。请参见示例LabelView.java类。

必须使用LinearLayout.LayoutParams(int-width、int-height、float-weight)

FrameLayout frameLayout = new FrameLayout(context);
LinearLayout.LayoutParams layPra = new LinearLayout.LayoutParams(width,height,mWeight);
layPra .gravity = Gravity.CENTER | Gravity.BOTTOM;
frameLayout .setLayoutParams(layPra );