making basic android app, xml help
<?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"
a开发者_C百科ndroid: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>
In my program the background shows up fine and so does the text, but the button does not appear. I feel like i am missing something basic, but i have looked it over and over again and cannot find anything. Any help appreciated
The problem was you were setting android:layout_width="fill_parent"
in TextView
, So it took full screen width just for displaying the TextView
.
So set android:layout_width="wrap_content"
to wrap up.
Same for the Button
.
Other things are :
LinearLayout
's android:orientation="horizontal | vertical"
It will add your components horizontally and vertically when set to horizontal and vertical respectively.
Modified Code I : Adding TextView and Button on Single Row...
<?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>
Modified Code II: Adding TextView and Button Vertically (Adding Components Vertically)...
Change LinearLayout
's orientation tag to vertical
android:orientation="vertical"
I'm not sure if it is really needed, but you could try adding android:orientation="vertical"
to the LinearLayout
精彩评论