制作基本的Android应用程序,xml帮助

时间:2011-07-14 07:20:29

标签: android 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:background="@drawable/world_series_celebration"
  >

<TextView 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:textSize="36dp" 
android:text="World Series Trivia" 
android:gravity="center"
/>

<Button
android:text="Click to Start"  
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:textSize="25dp"
/>

</LinearLayout>

在我的程序中,背景显示正常,文本也是如此,但按钮不会出现。我觉得我错过了一些基本的东西,但我一遍又一遍地看着它,找不到任何东西。任何帮助表示赞赏

2 个答案:

答案 0 :(得分:2)

问题是您在android:layout_width="fill_parent"中设置了TextView,因此仅显示TextView需要全屏宽度。

所以设置android:layout_width="wrap_content"来结束。

Button相同。

其他事情是:

LinearLayout的{​​{1}}

当分别设置为水平和垂直时,它将水平和垂直添加组件。

修改后的代码I:在单行上添加TextView和Button ...

android:orientation="horizontal | vertical"

修改后的代码II:垂直添加TextView和按钮(垂直添加组件)...

<?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="horizontal" android:background="@drawable/world_series_celebration" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="36dp" android:text="World Series Trivia" android:gravity="center" /> <Button android:text="Click to Start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25dp" /> </LinearLayout> 的方向标记更改为垂直

LinearLayout

答案 1 :(得分:0)

我不确定是否真的需要,但您可以尝试添加android:orientation="vertical" 到LinearLayout

相关问题