EditText background image fills parent

2019-08-28 01:21发布

问题:

I have EditText view like this:

<EditText 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="none"
    android:background="@drawable/writting_field"
    android:text="@string/test" />

But it stretches and fills parent. What is the problem?

回答1:

The problem may be Image size will be bigger enough so it occupying like FILL_PARENT. To get override this , use 9Patch images. So that it takes as much size as of the Text.



回答2:

If image size is same or bigger than parent it will automatically takes that much size , to take it fixed height width either you have to give it fixed height width in dp or try with ems option in edittext .