当前位置:首页 » 安卓系统 » android文字换行

android文字换行

发布时间: 2022-07-02 14:10:19

① android 中组件怎么换行

应用中获取会用到需要自动换行的控件,而这并不是一般的线性或者相对布局就能实现的,在此分享下自定义控件。原型是在网上找到的,在此稍作了修改。
这是设计出的样稿,样稿中的较高的图片是从一个数据集中的穿插在另一个数据集中的,Textview的长度需要根据文字的长度不同而设置,而左右需要平分,做法如下:

1.将总体分为两个数据集:左&右,并用2个LinearLayout分别装自定义控件

android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="5dip">

android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">

android:layout_width="fill_parent"
android:layout_height="wrap_content">
</<span style="line-height: 21px;">PredicateLayout>

android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<<span style="line-height: 21px;">PredicateLayout android:id="@+id/righttab"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</<span style="line-height: 21px;">PredicateLayout>

2.自定义控件
public class PredicateLayout extends LinearLayout {
int mLeft, mRight, mTop, mBottom;
Hashtable map = new Hashtable();
public PredicateLayout(Context context) {
super(context);
}
public PredicateLayout(Context context, int horizontalSpacing, int verticalSpacing) {
super(context);
}
public PredicateLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int mWidth = MeasureSpec.getSize(widthMeasureSpec);
int mCount = getChildCount();
int mX = 0;
int mY = 0;
mLeft = 0;
mRight = 0;
mTop = 5;
mBottom = 0;
int j = 0;
View lastview = null;
for (int i = 0; i < mCount; i++) {
final View child = getChildAt(i);

child.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
// 此处增加onlayout中的换行判断,用于计算所需的高度
int childw = child.getMeasuredWidth();
int childh = child.getMeasuredHeight();
mX += childw; //将每次子控件宽度进行统计叠加,如果大于设定的高度则需要换行,高度即Top坐标也需重新设置
Position position = new Position();
mLeft = getPosition(i - j, i);
mRight = mLeft + child.getMeasuredWidth();
if (mX >= mWidth) {
mX = childw;
mY += childh;
j = i;
mLeft = 0;
mRight = mLeft + child.getMeasuredWidth();
mTop = mY + 5;
//PS:如果发现高度还是有问题就得自己再细调了
}
mBottom = mTop + child.getMeasuredHeight();
mY = mTop; //每次的高度必须记录 否则控件会叠加到一起
position.left = mLeft;
position.top = mTop + 3;
position.right = mRight;
position.bottom = mBottom;
map.put(child, position);
}
setMeasuredDimension(mWidth, mBottom);
}
@Override
protected LayoutParams generateDefaultLayoutParams() {
return new LayoutParams(1, 1); // default of 1px spacing
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
int count = getChildCount();
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
Position pos = map.get(child);
if (pos != null) {
child.layout(pos.left, pos.top, pos.right, pos.bottom);
} else {
Log.i("MyLayout", "error");
}
}
}
private class Position {
int left, top, right, bottom;
}
public int getPosition(int IndexInRow, int childIndex) {
if (IndexInRow > 0) {
return getPosition(IndexInRow - 1, childIndex - 1)
+ getChildAt(childIndex - 1).getMeasuredWidth() + 8;
}
return getPaddingLeft();
}
}
3.将数据分别填充到左右两个控件中
这应该算是自动换行经典实例了吧,相信这个搞定以后同类型的需求都不成问题了。

② 安卓照片写数字为啥自动换行

是手机设置的问题,你把手机里面那个添加文字那个在设置设置新的功能就可以了。
在图片上面添加文字以后,他会有一定的空间显示,当你超出一定的字符范围或者是超出当前的空间,他会向下一个进行替换。除非你将字体变小或者是将空间拉大。一般编辑文字的时候,如果中间有空格的话,那么它就会自动换好了,你可以把那个空格去掉就可以了。

③ android文字自动换行每行文字数固定

只要设定好textview的宽,设具体的数值,,当设的textview的高足够高时,会自动换行并保持每行文字数固定
1) TextView在显示中文的时候 标点符号不能显示在一行的行首和行尾,如果一个标点符号刚好在一行的行尾,该标点符号就会连同前一个字符跳到下一行显示;
2)一个英文单词不能被显示在两行中( TextView在显示英文时,标点符号是可以放在行尾的,但英文单词也不能分开 );

如果只是想让标点符号可以显示在行尾,有一个简单的方法就是在标点符号后加一个空格,则该标点符号就可以显示在行尾了。

④ Android文本换行问题。

根据本人测试:将数据封装到模型类后,在Java文件中使用textViewObj.setText(obj.getXXX()).

无论是模拟器中,还是真机中,均可换行。

测试代码:

{

/**.*/

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

TextViewtx=(TextView)findViewById(R.id.hello);

Manm=newMan();

m.setAdd("aaaaa bbbb");

m.setName("dddd cccc");

tx.setText(m.getAdd());

}

}

Man类代码:

publicclassMan{

Stringname;

Stringadd;

publicStringgetName(){

returnname;

}

publicvoidsetName(Stringname){

this.name=name;

}

publicStringgetAdd(){

returnadd;

}

publicvoidsetAdd(Stringadd){

this.add=add;

}

}

附上一张运行图片吧。

⑤ 请问在Android中Textview换行显示问题,您如何解决

请问你的具体问题是什么?是如何让他换行显示么?我给你找了一些textview的属性:

android:ems 设置TextView的宽度为N个字符的宽度。
android:maxems 设置TextView的宽度为最长为N个字符的宽度。与ems同时使用时覆盖ems选项。
android:minems 设置TextView的宽度为最短为N个字符的宽度。与ems同时使用时覆盖ems选项。
android:maxLength 限制输入字符数。如设置为5,那么仅可以输入5个汉字/数字/英文字母。
android:lines 设置文本的行数,设置两行就显示两行,即使第二行没有数据。
android:maxLines 设置文本的最大显示行数,与width或者layout_width结合使用,超出部分自动换行,超出行数将不显示。
android:minLines 设置文本的最小行数,与lines类似。
android:lineSpacingExtra 设置行间距。
android:lineSpacingMultiplier 设置行间距的倍数。如”1.2”
android:numeric 如果被设置,该TextView有一个数字输入法。有如下值设置:integer正整数、signed带符号整数、decimal带小数点浮点数。
android:password 以小点”.”显示文本
android:phoneNumber 设置为电话号码的输入方式。
android:singleLine 设置单行显示。如果和layout_width一起使用,当文本不能全部显示时,后面用“…”来表示。如android:text="test_ singleLine " android:singleLine="true" android:layout_width="20dp"将只显示“t…”。如果不设置singleLine或者设置为false,文本将自动换行

android:textAppearance 设置文字外观。如“?android:attr/textAppearanceLargeInverse”这里引用的是系统自带的一个外观,?表示系统是否有这种外观,否则使用默认的外观。可设置的值如下:textAppearanceButton/textAppearanceInverse/textAppearanceLarge/textAppearanceLargeInverse/textAppearanceMedium/textAppearanceMediumInverse/textAppearanceSmall/textAppearanceSmallInverse
android:textColor 设置文本颜色
android:textColorHighlight 被选中文字的底色,默认为蓝色
android:textColorHint 设置提示信息文字的颜色,默认为灰色。与hint一起使用。
android:textColorLink 文字链接的颜色.
android:textScaleX 设置文字之间间隔,默认为1.0f。参见TextView的截图。
android:textSize 设置文字大小,推荐度量单位”sp”,如”15sp”
android:textStyle 设置字形[bold(粗体) 0, italic(斜体) 1, bolditalic(又粗又斜) 2] 可以设置一个或多个,用“|”隔开
android:typeface 设置文本字体,必须是以下常量值之一:normal 0, sans 1, serif 2, monospace(等宽字体) 3]

android:height 设置文本区域的高度,支持度量单位:px(像素)/dp/sp/in/mm(毫米)
android:maxHeight 设置文本区域的最大高度
android:minHeight 设置文本区域的最小高度
android:width 设置文本区域的宽度,支持度量单位:px(像素)/dp/sp/in/mm(毫米),与layout_width的区别看这里。
android:maxWidth 设置文本区域的最大宽度
android:minWidth 设置文本区域的最小宽度
【转自csdn】

希望能够帮到你

⑥ android中英文混编字符串如何实现文字自动换行

textView如果想要强制换行的话,必须先把TextView显示方式修改为多行(android:singleLine="false"),然后才能换行。
方法一般用两种:
1、在字符串里加入“\n”,如"abc\nrc";
2、把TextView设置为固定宽度,然后让系统自动换行。如android:layout_width="100dp";

⑦ 您好,请问你遇到的android textview 文字换行的问题是如何解决的,不胜感激

你可以重写一个LinearLayout,在里面添加textView,注意要记得布局应该改成水平布局,这样就可以了,或者你可以用相对布局,同样可以做到
<LinearLayout xmlns:android=""
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:text="人数:" android:id="@+id/number"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<EditText android:id="@+id/personNum" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>

安卓手机打字怎么换行

一般输入法都有换行按钮,向左箭头尾巴往上的标志

安卓系统手机使用百度手机输入法如何换行

以华为畅享7手机为例,可以通过以下方法在使用网络输入法时进行换行,步骤如下:

1、打开微信中的一个对话框,点击下面的输入栏进行文字的输入:

热点内容
scratch少儿编程课程 发布:2025-04-16 17:11:44 浏览:637
荣耀x10从哪里设置密码 发布:2025-04-16 17:11:43 浏览:366
java从入门到精通视频 发布:2025-04-16 17:11:43 浏览:82
php微信接口教程 发布:2025-04-16 17:07:30 浏览:308
android实现阴影 发布:2025-04-16 16:50:08 浏览:789
粉笔直播课缓存 发布:2025-04-16 16:31:21 浏览:339
机顶盒都有什么配置 发布:2025-04-16 16:24:37 浏览:210
编写手游反编译都需要学习什么 发布:2025-04-16 16:19:36 浏览:810
proteus编译文件位置 发布:2025-04-16 16:18:44 浏览:364
土压缩的本质 发布:2025-04-16 16:13:21 浏览:590