Reputation: 992
I have an edittext for which I want to set below background
but when I set this as background it stretches itself to fit in whole EditText like below image.
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
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.
Upvotes: 0
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
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