开发者

Android Layout - Text Too Wide?

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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜