强制将TextView变为mutiline,而不用\ n [英] Force TextView to mutiline without \n

查看:69
本文介绍了强制将TextView变为mutiline,而不用\ n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何想法,一旦文本视图中的空间用完,如何强制文本视图转到新行.我想发生的行为是,在没有以编程方式找出大小并强制换行的情况下,我希望它自己发生.

Any idea how I can force the textview to go to a new line once it runs out of space inside the view. The behaviour I want to happen is that without programatically findout out the size and forcing the newline I want it to happen by iteself.

在此代码中,它迫使按钮离开屏幕.

In this code it forces the buttons off the screen.

<TableRow>
                <TextView android:layout_width="fill_parent"
                    android:paddingLeft="5dp" android:paddingRight="5dp"
                    android:singleLine="false" android:layout_height="wrap_content"
                    style="@style/heading1" android:gravity="left" android:id="@+id/store_address"></TextView>

                <TableLayout android:layout_height="wrap_content"
                    android:layout_width="wrap_content" android:gravity="right">
                    <TableRow>
                        <ImageView android:id="@+id/img_user" android:gravity="right"
                            android:layout_width="wrap_content" android:layout_height="wrap_content"
                            android:scaleType="fitXY" android:src="@drawable/qrcode"
                            android:paddingBottom="2dp" />
                    </TableRow>
                    <TableRow>
                        <ImageView android:id="@+id/nfc" android:gravity="right"
                            android:layout_width="wrap_content" android:layout_height="wrap_content"
                            android:scaleType="fitXY" android:src="@drawable/nfc" />
                    </TableRow>
                </TableLayout>
            </TableRow>

推荐答案

将以下属性添加到 TextView 控件中:

add the following attribute to the TextView control:

android:maxWidth ="100dip" 在这里,我使用了100dip,您可以提供所需的任何尺寸.文字超过指定的宽度后,它将自动移至新行.

android:maxWidth = "100dip" Here i have used 100dip, you can give whatever dimensions you want. Once the text exceeds the specified width, it will automatically be shifted to a new line.

这篇关于强制将TextView变为mutiline,而不用\ n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆