Why dont my linear layout view gets displayed when i run my app
i have already created my xml file in which 4 layouts are used. now i want a linear layout to be displayed between my 3rd and fourth layout.i have set the width of this new layout to 0dp, for which i want the width to be changed to "wrap content" when my app is launched.
i have tried using the following code
LinearLayout layout = (LinearLayout)base.findViewById(R.id.layout);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
Log.w(TAG, "layout " +layout);
layout.setLayoutParams(params);
following is my layout in xml file
<LinearLayout android:layout_width="fill_parent" android:id="@+id/layout"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" android:layout_height="0dp"
>
<Button android:id="@+id/button1" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_width="wrap_content开发者_高级运维"
android:text="NO"
android:layout_marginLeft="50dp"
android:layout_marginTop="64dp"></Button>
<Button android:id="@+id/button2"
android:layout_alignParentRight="true" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="YES"
android:layout_marginRight="50dp"
android:layout_marginTop="64dp"></Button>
</LinearLayout>
but the layout value takes here as null.. Can anyone tell me how this can be solved..??? Thanks in advance..
You are probably missing the android schema and the height amount. Try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent" android:id="@+id/layout"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<Button android:id="@+id/button1" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_width="wrap_content"
android:text="NO"
android:layout_marginLeft="50dp"
android:layout_marginTop="64dp"></Button>
<Button android:id="@+id/button2"
android:layout_alignParentRight="true" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="YES"
android:layout_marginRight="50dp"
android:layout_marginTop="64dp"></Button>
</LinearLayout>
This might be because you have provided height as "0dip" here. android:layout_height="0dp".
Try to change it to "wrap_content" and try.
精彩评论