所以,最近我刚刚购买了Android编程的Big Nerd Ranch指南,并且我坚持使用第一部分代码。第二个LinearLayout应该低于TextView小部件,但由于某种原因拒绝并且正在将第二个LinearLayout推到文本的一侧,只允许其中一个按钮可用。我尝试将api更改为不同版本的Android都无济于事,bignerdranch.com论坛上充满了垃圾邮件机器人,实际上回答的问题很少。 简而言之,我只需要想办法将第二个LinearLayout移到TextView下面。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientaion="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:text="@string/question_text" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/true_button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/false_button" />
</LinearLayout>
</LinearLayout>
答案 0 :(得分:2)
LinearLayout
默认为horizontal
方向。您拼错了orientation
:您有android:orientaion
并且在运行时会忽略输入错误的属性(尽管Android Studio应该抱怨)。
答案 1 :(得分:0)
使用以下xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientaion="vertical" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView"
android:gravity="center"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="New Button"
android:layout_weight="1"
android:id="@+id/button1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="New Button"
android:layout_weight="1"
android:id="@+id/button2" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>