获得edittext的图片大小

1.在布局文件中编写控件,有2张图片

 <EditText
        android:id="@+id/edit"
        android:background="@drawable/rounded_edittext"
        android:drawableRight="@drawable/delete"
        android:drawableLeft="@drawable/search"
        android:drawablePadding="8dp"
        android:singleLine="true"
        android:hint="请输入..."
        android:imeOptions="actionSearch"
        android:layout_width="match_parent"
        android:layout_height="45dp"/>

2.在activity中读取

EditText editText =findViewById(R.id.edit);

        Drawable[] drawables= editText.getCompoundDrawables();
        int size= drawables.length;
        for(int i=0;i<size;i++){
           Drawable drawable =drawables[i];
           if(drawable!=null){
               Log.d(TAG, "a:"+drawable.getBounds().width()+"高度:"+drawable.getBounds().height());
           }else{
               Log.d(TAG, "a: ");
           }
        }

3.实际效果

 

4.顺序是左上右下

 

posted @ 2018-01-09 09:14  layfork  阅读(212)  评论(0编辑  收藏  举报