Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android set margin/padding for contents (text) instead of a container (EditText)

What I want to do is add some top margin/padding before THE TEXT, and not for the entire container:

Code is as simple as:

<EditText android:id="@+id/mightyText"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:gravity="left|top"
     android:inputType="textAutoComplete|textMultiLine"
     android:paddingLeft="20dp"
     android:paddingRight="20dp"
     android:paddingBottom="80dp"
     android:background="#fff" />

Produces outputs:

Desired behaviour

Once it's on top it works great. I have equal paddings for sides and top...


Naughty padding ;(

...but when I scroll, the padding stays glued to the container instead of going up with the text


And that's how I'd like it to be (when not scrolled to top):

Proper behavior

How do I change it, so it scrolls with the text instead of always being visible?

like image 1000
meeDamian Avatar asked Sep 12 '13 21:09

meeDamian


1 Answers

Put it in ScrollView, which will automatically take care of the scroll. EditText won't be responsible for that, so his padding will work as you wish. Try the code below:

<ScrollView
           android:layout_width="match_parent"
           android:layout_height="wrap_content" >

           <EditText android:id="@+id/mightyText"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:gravity="left|top"
               android:inputType="textAutoComplete|textMultiLine"
               android:paddingLeft="20dp"
               android:paddingRight="20dp"
               android:paddingBottom="80dp"
               android:background="#fff" />

</ScrollView>
like image 126
ezpn Avatar answered Nov 02 '22 20:11

ezpn