Fihop
Fihop

Reputation: 3177

google search style layout android

I'd like to have the following figures style layout.

My xml code:

<RelativeLayout android:id="@+id/RelativeLayout01"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:orientation="vertical" 
android:layout_height="fill_parent">

<LinearLayout
    android:id="@+id/LinearLayout01"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageViewFlickrLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/edit_message"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/edit_message" />

    <Button
        android:id="@+id/button_search"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="searchUsingTag"
        android:text="@string/button_search" />
</LinearLayout>

</RelativeLayout>

The problem is that ImageView doesn't show and button is at the left. Actually, I want ImageView and editText and button showing in the center.

enter image description here

Upvotes: 0

Views: 410

Answers (2)

TronicZomB
TronicZomB

Reputation: 8747

Try the following:

<RelativeLayout android:id="@+id/RelativeLayout01"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout
    android:id="@+id/LinearLayout01"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageViewFlickrLogo"
        android:src="@drawable/name_of_your_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

    <EditText
        android:id="@+id/edit_message"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/edit_message"
        android:layout_gravity="center"  >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button_search"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="searchUsingTag"
        android:text="@string/button_search" 
        android:layout_gravity="center" />
</LinearLayout>

</RelativeLayout>

Thanks to Anirudha Agashe for catching the missing image. I have added it in here as well.

Upvotes: 2

Anirudha Agashe
Anirudha Agashe

Reputation: 3530

You haven't set what image you want to display in image view. You can do this using following code.

 android:src="@drawable/name_of_your_image" 

assuming you have put in drawable folder. Or you will have to set the source of the image view to some image through the code.

Upvotes: 1

Related Questions