Skip
Skip

Reputation: 6521

In Android: how to force a TextView to wrapt the content AND padding

How would I make the TextView_height=content_height+padding When I am adding some top-padding to the textbox - it moves the content behind the borders of the TextView. This is right, since I made the TextView to be as tall as the content.

Is it possible to make the TextView as tall as content + padding?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
tools:context=".DisplayActivity" >

<TextView
    android:id="@+id/TopmessageStripe"
    style="@style/TopmessageStripeTheme"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_alignWithParentIfMissing="false"
    android:layout_centerHorizontal="true"
    android:height="@dimen/big_margin"
    android:paddingTop="5dp"
    android:text="TextView" />

    </RelativeLayout>

enter image description here

Upvotes: 0

Views: 132

Answers (2)

yarakyo
yarakyo

Reputation: 499

This is most likely your problem

android:height="@dimen/big_margin"

It is setting a custom height instead of wrapping the content.

Upvotes: 2

Cob50nm
Cob50nm

Reputation: 961

Not sure how to do it using the gui but this might be what you're looking for in the xml for the text view

<TextView 
        android:id="@+id/mTextView"
        android:paddingTop="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"      
        >
    </TextView>

Upvotes: 0

Related Questions