A bug of the 2d layout engine of Android?
If you add only one button in a whole new Activity, the screen looks like this:
<?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">
<Button android:id="@+id/Button01"
android:layout_height="wrap_content"
android:text="false"
android:layout_width="wrap_content" ></Button>
</LinearLayout>
But if you add a ListView, then everything is OK:
<?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">
<ListView android:layout_width="fill_parent"
android:id="@+id/contactList"
android:layout_height="wrap_conte开发者_如何学Gont"
android:layout_weight="1"/>
<Button android:id="@+id/Button01"
android:layout_height="wrap_content"
android:text="false"
android:layout_width="wrap_content" ></Button>
</LinearLayout>
EDIT: This only happened in QVGA mode. HVGA mode worked fine.
I don't see what the problem is. This makes perfect sense. In your first layout you used fill_parent on the linear layout and wrap_content on the button.
The button did exactly what it was supposed to. It filled it's width and height using the width/height of the text inside as dictated by wrap_content.
If you are expecting the button to fill the whole screen, you need to use fill_parent on the actual view.
Edit: Your code works perfectly fine for me in HVGA, QVGA, and WVGA.
精彩评论