Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NinePatch two textbox with one image

Tags:

android

I want to implement this image enter image description here

area textbox1 and textbox2 ninepatch able

enter image description here

how can I ninepatch exactly this ??

like image 331
Saeed Hashemi Avatar asked Jan 13 '13 08:01

Saeed Hashemi


2 Answers

There is one constraint with android 9-patch : the content area defined by right and bottom borders must be continuous (i.e. you can only have one segment on right and bottom border).

On the other hand you can have multiple stretchable area defined by segments on the top and left borders.

In your case :

for the stretchable areas :

  • draw one segment on the left border

  • draw two segments (of the same lenght) on top border (symetric around the vertical divider but don't include the vertical divider in them).

for the content area:

  • draw one segment on bottom border
  • draw one segment on the right border

For the content:

  • define a horizontal linear layout with 2 TextView in it (width = 0dp and weight = 1.0 for both)
  • use your nine patch image as background

Hope this help.

----------------------------------------------------------------------------

Result :

I use your plan but result is this enter image description here

when my text increase Textbox height don't increase

how can fix that ?

----------------------------------------------------------------------------

I don't think it's linked to the 9-patch image. It's more likely related to the textView.

try : on the textView

android:layout_height="WRAP_CONTENT"

on the linear layout

android:layout_height="WRAP_CONTENT"
like image 177
ben75 Avatar answered Nov 06 '22 16:11

ben75


LinearLayout allows you to specify dividers between its children. So you need to:

  1. Put your TextViews inside a horizontal LinearLayout
  2. Assign your rounded rectangle 9-patch without divider as a background of LinearLayout
  3. Add dividers to your LinearLayout: android:divider="drawable_resource"
    android:showDividers="middle"

This layout is also more flexible - you don't need to make another 9-patch in case you want 3 or more TextViews

like image 21
Andrii Chernenko Avatar answered Nov 06 '22 18:11

Andrii Chernenko