Reputation: 7149
I want to put an Icon inside an EditText
so I did like this:
android:drawableLeft="@drawable/search_icon"
The problem is that the image is bigger than the EditTex
t so the EditText
becomes bigger in order to fit the image size. What I want is the opposite: The image should resize in order to fit the EditText
height, is it possible?
I (desperately) tried with:
android:adjustViewBounds="true"
But obviously it doesn't work.
Is there any way to do so?
Upvotes: 6
Views: 7092
Reputation: 1061
You can simply do this by fixing the height of the edit text.
<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>
you can use below code for resizing
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);
Upvotes: 0
Reputation: 2436
Try
<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>
Upvotes: 2
Reputation: 141
You can wrap in RelativeLayout , on the left set an ImageView with layout_height match_parrent
Upvotes: 0