2011-09-06 59 views
0

我已经创建了使用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

请显示:1)XML文件,其中ID'layout'被定义和2)你如何加载'base'。 –

+0

在我的方法中,我的方法使用了这个基础,在这部分代码中写入了.. – JKV

+0

重新读完你的问题之后,难道你不能从总共5个布局开始,并在第3个和第4个“在你的XML中可见性=“已经消失”了 - 如果你想显示它,只需设置'visibility =“visible”'。这样你就不需要对尺寸/布局参数做任何事情。 –

回答

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> 
0

这可能是因为您在此处提供了“0dip”高度。 android:layout_height =“0dp”

尝试将其更改为“wrap_content”并尝试。

相关问题