I am new to android.
I face one problem that is i am adding frame layout to my application the code is
<?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"
开发者_StackOverflow社区 android:id="@+id/linearLayout1"
android:layout_width="fill_parent">
</LinearLayout>
</FrameLayout>
</LinearLayout>
My problem is i want to change the frame layout height in different screen orientations
the sample code is
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));
}
But it gives force close ,
if any one has idea please help me.
Thanks in advance.
You have to use 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 );
One way is to build a custom view and override the onLayout and onMeasure functions. In the onLayout function you can override the width and the height. See the example LabelView.java class here.
精彩评论