anshul
anshul

Reputation: 992

Edittext background stretches to fill the entire area

I have an edittext for which I want to set below backgroundenter image description here

but when I set this as background it stretches itself to fit in whole EditText like below image.enter image description here

and below is my code for xml file for editext

<LinearLayout
    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:visibility="visible" >

    <EditText
        android:id="@+id/comment"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_weight="1"
        android:hint="@string/add_your_comment"
        android:imeOptions="actionDone"
        android:padding="5dp"
        android:background="@drawable/bg_search_field"
        android:scrollHorizontally="true"
        android:singleLine="true" />

    <ImageView
        android:id="@+id/post_comment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:padding="5dp"
        android:layout_marginRight="@dimen/fifteen_dp"
        android:src="@drawable/tick_selection" />
</LinearLayout>

How can I set the background correctly?

Upvotes: 0

Views: 332

Answers (3)

Hareshkumar Chhelana
Hareshkumar Chhelana

Reputation: 24848

// try this
<LinearLayout
            android:id="@+id/footer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:visibility="visible" >

        <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center_vertical">
            <EditText
                    android:id="@+id/comment"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:hint="add_your_comment"
                    android:imeOptions="actionDone"
                    android:padding="5dp"
                    android:background="@drawable/bg_search_field"
                    android:scrollHorizontally="true"
                    android:singleLine="true" />
        </LinearLayout>

        <ImageView
                android:id="@+id/post_comment"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:padding="5dp"
                android:layout_marginRight="@dimen/fifteen_dp"
                android:src="@drawable/tick_selection" />
    </LinearLayout>

   // also use my uploaded image which is editext background i'm apply 9-patch so now it not stretched if editext width is large.

enter image description here

Upvotes: 0

anshul
anshul

Reputation: 992

Ok So issue resolved simply by using nine patch image i have got from actionBarsherlock library which is using it for it's search view.

Upvotes: 1

ssantos
ssantos

Reputation: 16526

This line.-

android:layout_weight="1"

makes your TextView fill the empty width in the LinearLayout. Just try and remove it. You should also replace

android:padding="5dp"

for

android:layout_margin="5dp"

Upvotes: 0

Related Questions