<?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_height="fill_parent"
android:layout_width="wrap_content"
android:text="这里是main2a"
/>
<Button android:id="@+id/button2"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:text="上一个Activity"
/>
</LinearLayout>
今天写了这么一个布局的XML,太不小心,看上去没哪错,但调试了好几遍,TextView和Button两个只能显示一个,而且哪个放上面就显示哪一个,很郁闷啊。弄了差不多半小时还没找出问题。后来一看才恍然大悟啊,原来是自己不小心写错了:
android:layout_height="fill_parent"
垂直方向上的布局成了fill_parent,也就是说TextView垂直方向上把<LinearLayout>占满了,而<LinearLayout>也是垂直布局,所以Button就没地方来显示了。太不小心了,把fill_parent改成wrap_content就OK了。