2015-07-15 9 views
5

voglio mettere un'icona all'interno di un EditText così ho fatto in questo modo:immagine EditText leftView adattarsi alle dimensioni del EditText Android

android:drawableLeft="@drawable/search_icon" 

Il problema è che l'immagine è più grande della EditTex t in modo che il EditText diventa più grande per adattarsi alla dimensione dell'immagine. Quello che voglio è il contrario: l'immagine dovrebbe ridimensionarsi per adattarsi all'altezza EditText, è possibile?

I (disperatamente) provato con:

android:adjustViewBounds="true" 

Ma ovviamente non funziona.

C'è un modo per farlo?

+0

Android: layout_height = "wrap_content"? – sasikumar

+0

@sasikumar è già impostato su wrap_content, ho anche provato a impostare un'altezza personalizzata ma l'immagine viene tagliata – Signo

+0

le dimensioni dell'immagine? – sasikumar

risposta

1

È possibile farlo semplicemente fissando l'altezza del testo di modifica.

<EditText 
    android:id="@+id/editText1" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:ems="10" 
    android:drawableLeft="@drawable/beautiful" 
    android:inputType="textPersonName" > 

    <requestFocus /> 

</EditText> 

è possibile utilizzare sotto codice per il ridimensionamento

Drawable d = imageView.getDrawable(); 
    Bitmap bitmap = ((BitmapDrawable) d).getBitmap(); 
    byte[] ba; 
    do { 
     ByteArrayOutputStream bao = new ByteArrayOutputStream(); 

     Log.e("BEFORE REDUCING", 
       bitmap.getHeight() + " " + bitmap.getWidth() + " " 
         + bitmap.getRowBytes() * bitmap.getHeight()); 

     bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bao); 
     Log.e("After REDUCING", 
       bitmap.getHeight() + " " + bitmap.getWidth() + " " 
         + bitmap.getRowBytes() * bitmap.getHeight()); 
     ba = bao.toByteArray(); 
     if ((ba.length/1024) >= 650) { 
      bitmap = Bitmap.createScaledBitmap(bitmap, 
        (int) (bitmap.getWidth() * 0.95), 
        (int) (bitmap.getHeight() * 0.95), true); 

     } 

     Log.e("BYTE LENGTH", "" + ba.length/1024); 

    } while ((ba.length/1024) >= 650); 
+0

Questo non funziona – rst

0

Puoi avvolgere in RelativeLayout, a sinistra impostare un ImageView con match_parrent layout_height

1

Prova

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#dd80aa" 
android:orientation="vertical"> 

<RelativeLayout 
    android:layout_width="363dp" 
    android:layout_height="wrap_content"> 

    <EditText 
     android:id="@+id/editText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="Enter text here" 
     android:marginLeft="50dp"/> 

    <ImageView 
     android:layout_width="wrap_contenta" 
     android:layout_height="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:layout_gravity="right" 
     android:src="@android:drawable/ic_menu_search"/> 

</RelativeLayout> 


</LinearLayout>