2013-10-13 6 views
0

У меня есть EditText, для которого я хочу, чтобы установить ниже Backgroud enter image description hereEditText Backgroud streches, чтобы заполнить всю область

но когда я установил это как Backgroud он streches себя, чтобы соответствовать в целом EditText, как показано ниже изображения. enter image description here

и ниже мой код для XML-файла для 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> 

Позвольте мне знать, как я могу установить фон правильно

ответ

0

Это line.-

android:layout_weight="1" 

делает ваш TextView заполните пустую ширину в LinearLayout. Просто попробуйте удалить его. Вы должны также заменить

android:padding="5dp" 

для

android:layout_margin="5dp" 
+0

я попытался это, но не повезло :( – anshul

+0

ММХ, что обивка может быть баловаться с фоном попу хорошо. На самом деле, видя нижнюю границу, кажется, изображение растяжение более вертикально, чем горизонтально. Попробуйте устанавливая поле вместо заполнения. – ssantos

+0

Я тоже пробовал это, но мне не повезло. Думаю, это потому, что мы устанавливаем backgroud edittext, который пытается растянуть его, чтобы он соответствовал редактированию.Однако, что я могу сделать, чтобы решить эту проблему – anshul

1

ИТАК Устранена просто используя девять патч изображение я получил от библиотеки ActionBarSherlock, которая использует его для это вид поиска.

0
// 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

Смежные вопросы