我已经创建了我的xml文件,其中使用了4个布局。现在我想要在我的第3和第4个layout之间显示一个线性布局。我已经将这个新布局的宽度设置为0dp,我希望在我的应用程序启动时将宽度更改为“换行内容”。
我尝试使用以下代码
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);
以下是我在xml文件中的布局
<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>
但布局值在这里取为空..有谁能告诉我这是如何解决的.. ??? 提前谢谢..
答案 0 :(得分:1)
您可能缺少Android架构和高度数量。试试这个
<?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>
答案 1 :(得分:0)
这可能是因为你在这里提供了高度为“0dip”。的机器人:layout_height = “0dp”强>
尝试将其更改为“ wrap_content ”并尝试。