现在我只是创建一个简单的页面。但是,除了第一个 TextView 之外,没有任何内容弹出。
我尝试通过项目>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/