Roman Panaget
Roman Panaget

Reputation: 2428

Having some problems with the XML layouts (android development)

I've just started learning the android lessons about android development. I was creating a text editor where you enter a message, you set some options and it display your message but i had a problem with the XML file, I set a Button in order to display the message but this button is not displayed. Here is the XML file of my layout:

   <?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:orientation="vertical"
    android:gravity="center_horizontal"
    android:padding="12dp" >

    <TextView android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="@string/text_editor"
        android:textSize="@dimen/font_text_view"
        android:textColor="@color/white"
        android:paddingBottom="20dp" />

    <EditText android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/edit_text_hint"/>

    <LinearLayout android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:gravity="center_horizontal"
        android:padding="12dp" >

        <TextView android:id="@+id/text_color_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/text_color"
            android:textSize="@dimen/font_button"
            android:textColor="@color/black"
            android:paddingRight="20dp" />

        <Button android:id="@+id/black_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/black"
            android:textSize="@dimen/font_button"
            android:textColor="@color/black"/>

        <Button android:id="@+id/red_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/red"
            android:textSize="@dimen/font_button"
            android:textColor="@color/black"/>

        <Button android:id="@+id/green_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/green"
            android:textSize="@dimen/font_button"
            android:textColor="@color/black"/>

    </LinearLayout>

    <Button android:id="@+id/display_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="@string/display_message"
        android:textSize="@dimen/font_button"
        android:textColor="@color/black"/>

</LinearLayout>

Eclipse doesn't throw any exception that's why I don't understand. Here is the displayed layout: The display_button is not displayed...

Upvotes: 0

Views: 82

Answers (1)

MSA
MSA

Reputation: 2482

Found your problem:

Change from

   <LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:gravity="center_horizontal"
    android:padding="12dp" >

To:

 <LinearLayout android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center_horizontal"
    android:padding="12dp" >

The android:layout_height="match_parent" was forceing your button be be out of the screen

RESULT:

Before Change:

enter image description here

After change

enter image description here

Upvotes: 3

Related Questions