tags:

views:

658

answers:

2

How to align the text to top of a TextView?
Equivalent Android API for Swings setInsets()?
that is top of text should start be in (0,0) of TextView

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical">

    <TextView 
        android:id="@+id/text1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="TextView" 
        android:textSize="42sp" 
        android:paddingTop="0px" 
        android:gravity="top">
    </TextView> 
</LinearLayout>

I have used above snippet, however still output is not as expected
Any ideas?

A: 

Im not sure if i understand what you are meaning, but the text inside the textview is going to be align to the top if you use gravity=top on the text-view.

If you put a backgrund color on you textview you might see better what is happening...

I guess you problem is that the textview is centered since you use fill_parent on both height and width on the parent LinearLayout. The textview seems to be the only child so try putting gravity=top on the LinearLayout...

Thats the only thing i could think of...

PHP_Jedi
I have tried that too, however no use..
Riyaz Mohammed Ibrahim
+1  A: 

I think your snippet is right. I guess you are bothered by some pixels between top of the letter "T" and top edge of the TextView? This space is required to render some letters that are not present in English alphabet.

Check that links to get idea:

alex2k8
Yeah, you are correct, it's better if we have some control on this, like override this default behavior by our own.
Riyaz Mohammed Ibrahim