Android 为什么我的线性布局视图在运行应用程序时不显示

Android 为什么我的线性布局视图在运行应用程序时不显示,android,Android,我已经创建了使用了4种布局的xml文件。现在我想在我的第三和第四个版面之间显示一个线性版面。我已经将这个新版面的宽度设置为0dp,我想在我的应用程序启动时将宽度更改为“包装内容” 我已尝试使用以下代码 LinearLayout layout = (LinearLayout)base.findViewById(R.id.layout); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(

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

但是布局值在这里为null。。谁能告诉我如何解决这个问题。。???
提前感谢。

这可能是因为您在此处提供的高度为“0dip”android:layout\u height=“0dp”


尝试将其更改为“包装内容”,然后重试

您可能缺少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)定义了ID
布局的XML文件以及2)如何加载
base
。在我的方法中,base用作编写这部分代码的视图。在再次阅读您的问题后,您能否从总共5个布局开始,并将其设置为第3和第4个布局之间的布局
在XML中——如果您想显示它,只需设置
visibility=“visible”
。这样,您不需要对大小/布局参数进行任何操作。需要更多信息。需要Xml文件。