Why is my second LinearLayout not showing?
I have just decided to try out the Android SDK, so I installed it and now I'm trying to make a simple interface using an XML file for a calculator I've made and that I might port to Android.
Here a first draft of the XML file I want to use:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="3"
android:text="To evaluate an expression, type it below."
/>
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/btnFunctions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Functions"
/>
<Button
android:id="@+id/btnConversions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Conversions"
/>
<Button
android:id="@+id/btnConstants"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Constants"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/btnGraphs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Graphs"
/>
<Button
android:id="@+id/btnStats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stats"
/>
开发者_开发技巧 </LinearLayout>
</LinearLayout>
However, when I run ant install
and try out the app on the emulator, the last two buttons in the last (nested) LinearLayout, btnGraphs and btnStats, do not show up at all (the rest is fine).
What am I doing wrong?
You should change the layout_height of the LinearLayout with three buttons to "wrap_content" it is filling up the screen so you can't see the other LinearLayout.
your first Linearlayout is::
android:layout_height="fill_parent"
change to::
android:layout_height="wrap_content"
The layout_height of your first embedded LinearLayout is set to "fill_parent". This means it is going to take up all of the space on the screen, and thus the things below it will not get rendered. Try changing it to "wrap_content" to only take up as much space as is needed.
精彩评论