我已经创建了使用4个布局的我的xml文件。现在我想要在我的第三和第四个布局之间显示一个线性布局。我已经将这个新布局的宽度设置为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>
但布局值取这里空..谁能告诉我这可怎么解决了..??? 在此先感谢..
请显示:1)XML文件,其中ID'layout'被定义和2)你如何加载'base'。 –
在我的方法中,我的方法使用了这个基础,在这部分代码中写入了.. – JKV
重新读完你的问题之后,难道你不能从总共5个布局开始,并在第3个和第4个“在你的XML中可见性=“已经消失”了 - 如果你想显示它,只需设置'visibility =“visible”'。这样你就不需要对尺寸/布局参数做任何事情。 –