java - 图形布局和运行时的奇怪问题

标签 java android xml eclipse view

现在我只是创建一个简单的页面。但是,除了第一个 TextView 之外,没有任何内容弹出。

Graphical layout Image

Emulator Image

我尝试通过项目>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>

最佳答案

问题是因为你到处都有“match_parent”:) 对于除父 LinearLayout 之外的所有布局,尝试使用layout_width="wrap_content"和layout_height="wrap_content"

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

关于java - 图形布局和运行时的奇怪问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8947130/

相关文章:

java - 无法使图像在 jpanel 上消失

javascript - 在 sqlite 中出现错误,例如 ionic1 中的查询

android - 获取启动器 Activity 名称

php - 要使用 CSV 或 XML 进行数据导入?

java - 如何强制 HyperJaxb 生成 toString() 方法?

java - 错误消息未传递 - 失败消息为空?

java.security.NoSuchAlgorithmException : AES KeyGenerator not available while deploy on jboss

android - 如何在 Broadcast Receiver 的接收事件中使用倒数计时器?

android - 单击更改 TextView 背景颜色

javascript - 如何单击自动构建的 li 列表的功能