tags:

views:

47

answers:

1

I have a View comprised of two TextView if first is too wide can I get the second to display on the next line?

Is there a solution?

<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<TextView android:text="If this text is too wide"
android:textSize="20px"
android:textStyle="bold"
android:id="@+id/del01"
android:paddingTop="3px"
android:paddingBottom="3px"
android:gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView android:text="I want this on a different line"
android:id="@+id/del02"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</LinearLayout>
A: 

Create your own view class derived from View and display both texts in that view. Override draw() and you can do whatever you want there depending on the sizes of the text.

Note: It is usually not a good idea to define sizes and paddings in "px". You should rather use "dp" which will be automatically scale on different screen sizes and densities.

StefanMK
Got it!!!!have two views v2a and v2bv1.measure(v1.getWidth(),v1.getHeight());v2a.measure(v2a.getWidth(),v2a.getHeight());if (lv.getWidth()< (v1.getMeasuredWidth()+v2a.getMeasuredWidth())) //too big v2a.setVisibility(View.GONE);else v2b.setVisibility(View.GONE);thanks for the thoughts anywaySteve
Milk Round