[英]EditText leftView image fit the size of the EditText Android
我想在EditText
放置一個Icon,所以我喜歡這樣:
android:drawableLeft="@drawable/search_icon"
問題是圖像比EditTex
大,因此EditText
變大以適應圖像大小。 我想要的是相反的:圖像應調整大小以適應EditText
高度,是否可能?
我(拼命地)嘗試:
android:adjustViewBounds="true"
但顯然它不起作用。
有沒有辦法這樣做?
嘗試
<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>
您可以通過修改編輯文本的高度來完成此操作。
<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>
你可以使用下面的代碼來調整大小
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);
你可以在RelativeLayout中包裝,在左邊設置一個帶有layout_height match_parrent的ImageView
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.