Reputation: 2684
I have a TextView in a FrameLayout with a background that is 150 x 53 pixels, but when my app loads, the background takes up the whole width of the view, I only desire it to take up the width of the text. How might I do this?
<TextView
android:id="@+id/txtPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dip"
android:layout_marginTop="164dip"
android:adjustViewBounds="true"
android:layout_gravity="top|center"
android:gravity="center"
android:textStyle="bold"
android:textSize="46dip"
android:textColor="#ffffff"
android:background="@drawable/greenbg"
android:text="$0.00" />
Upvotes: 0
Views: 6951
Reputation: 51
I think this is happening because of this "android:background="@drawable/greenbg", isn't it? try to remove it test the app. if this drawable has a big width, the textView will became big too.
Upvotes: 2
Reputation: 3025
try this:
<TextView
android:id="@+id/txtPrice"
android:layout_width="150dp"
android:layout_height="53dp"
android:layout_marginLeft="60dip"
android:layout_marginTop="164dip"
android:adjustViewBounds="true"
android:layout_gravity="top|center"
android:gravity="center"
android:textStyle="bold"
android:textSize="46dip"
android:textColor="#ffffff"
android:background="@drawable/greenbg"
android:text="$0.00" />
you have to give the layout_height and layout_width fix according to framelayout size.
Upvotes: 1