Reputation: 1164
What I want to do is add some top margin/padding before THE TEXT, and not for the entire container:
<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" />
Once it's on top it works great. I have equal paddings for sides and top...
...but when I scroll, the padding stays glued to the container instead of going up with the text
How do I change it, so it scrolls with the text instead of always being visible?
Upvotes: 17
Views: 34967
Reputation: 1748
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>
Upvotes: 27
Reputation: 334
On ViewGroup there is attribute called clipToPadding
. Docs says:
Defines whether the ViewGroup will clip its drawing surface so as to exclude the padding area. This property is set to true by default.
Try to find out something similar in EditText.
Upvotes: 0
Reputation: 2272
Does it have to be an EditText? If the user will not be editing it, then use a normal TextView with a top padding of 10dp and wrap it in a ScrollView.
As far as I know, there's no way to set an internal padding on the top of an EditText.
Upvotes: 0