【问题标题】:Strange issue on graphical layout and on runtime图形布局和运行时的奇怪问题
【发布时间】:2012-01-20 19:56:38
【问题描述】:

现在我只是创建一个简单的页面。但是除了第一个 textview 之外什么都没有弹出。

Graphical layout Image

Emulator Image

我试图通过 project>clean 进行清理。奇怪的是,这只发生在这个 xml 上。其他人似乎工作。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout 
        android:layout_width="match_parent"
      android:layout_height="match_parent" 
        >
    <TextView 
      android:layout_width="match_parent"
      android:layout_height="match_parent" 
      android:text="Background Color: "/>

    <Spinner 
        android:id="@+id/Spinner"
          android:layout_width="match_parent"
          android:layout_height="match_parent" 
        />
    </LinearLayout>

    <LinearLayout 
        android:layout_width="match_parent"
      android:layout_height="match_parent" 
        >    
    <TextView 

        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:text="Size: "        />

    <RadioGroup 
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:orientation="vertical"
        >
        <RadioButton 
            android:id="@+id/small"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Small"
            />
        <RadioButton 
            android:id="@+id/medium"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Medium"
            />
        <RadioButton 
            android:id="@+id/large"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Large"
            />

    </RadioGroup>
    </LinearLayout>

        <Button
            android:id="@+id/Make_Changes"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Confirm"/>

</LinearLayout>

【问题讨论】:

  • 对不起,关于长 xml 代码的家伙我真的不喜欢在 stackoverflow 上发布这样的东西,但我真的没有想法。

标签: java android xml eclipse view


【解决方案1】:

问题是因为你到处都有“match_parent”:) 尝试 layout_width="wrap_content" 和 layout_height="wrap_content" 除了父 LinearLayout

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout 
        android:layout_width="wrap_content"
      android:layout_height="wrap_content" 
        >
    <TextView 
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" 
      android:text="Background Color: "/>

    <Spinner 
        android:id="@+id/Spinner"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" 
        />
    </LinearLayout>

    <LinearLayout 
        android:layout_width="wrap_content"
      android:layout_height="wrap_content" 
        >    
    <TextView 

        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="Size: "        />

    <RadioGroup 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:orientation="vertical"
        >
        <RadioButton 
            android:id="@+id/small"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Small"
            />
        <RadioButton 
            android:id="@+id/medium"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Medium"
            />
        <RadioButton 
            android:id="@+id/large"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Large"
            />

    </RadioGroup>
    </LinearLayout>

        <Button
            android:id="@+id/Make_Changes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Confirm"/>

</LinearLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-17
    • 2014-06-12
    • 1970-01-01
    • 2020-09-10
    • 1970-01-01
    • 2020-03-29
    • 1970-01-01
    • 2013-11-15
    相关资源
    最近更新 更多