android布局换行
⑴ android怎么让一段长的代码自动换行
android开发使用的是eclipse或者android studio,内置的一个快捷键:ctrl+shift+F,可以自动变换格式,一些长得代码就会自动换行。
android开发工具会提供很多快捷键,比如alt+方向键实现移动代码等等。
⑵ linearlayout怎么换行
LinearLayout换行:设置成垂直布局android:orientation="vertical"
如果有些要同一行,有些要换行,则把要换行的用LinearLayout括起来,设置成vertical
如:
1
2
3
4
5
6
7
8
<LinearLayout>
<TextView/>//TextView和下面的LinearLayout是并排的
<LinearLayout
android:orientation="vertical"> //里面是TextView占一行,Button占一行
<TextView/>
<Button/>
</LinearLayout>
</LinearLayout>
⑶ android文字自动换行每行文字数固定
只要设定好textview的宽,设具体的数值,,当设的textview的高足够高时,会自动换行并保持每行文字数固定
1) TextView在显示中文的时候 标点符号不能显示在一行的行首和行尾,如果一个标点符号刚好在一行的行尾,该标点符号就会连同前一个字符跳到下一行显示;
2)一个英文单词不能被显示在两行中( TextView在显示英文时,标点符号是可以放在行尾的,但英文单词也不能分开 );
如果只是想让标点符号可以显示在行尾,有一个简单的方法就是在标点符号后加一个空格,则该标点符号就可以显示在行尾了。
⑷ 安卓手机打字怎么换行
一般输入法都有换行按钮,向左箭头尾巴往上的标志
⑸ 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放在一个LinearLayout中,请问如何将TextView中的文字自动换行或者修改布局实现
首先TextView的height设置成wrapcontent
其次TextView的singleLine属性不设置
⑺ 请问在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界面布局,如何布局一个跟分辨率无关的,自动换行的界面
刚才打了一遍,结果提交的时候浏览器崩溃了,真悲剧!再重打一遍吧。
首先,我们的布局文件*.xml都是放在android的工程下的layout这个目录下的。其实。android还支持
横屏和竖屏切换的时候,系统调用不一样的布局xml。比如你的一个activity用到的布局文件叫做main.xml 你实现一个竖屏的main.xml放在layout-port这个目录下 实现一个横屏main.xml放在layout-land这个目录下。(这两个目录自己建)系统会自动去这两个目录中找到对应的xml文件。同样的对于不同分辨率的屏幕。系统也支持。比如一个320*480 一个600*1024.你新建一个layout-320*480 实现一个main.xml让它一行显示三个无间隔,将这个xml放进去。再实现一个一行放四个有间隔的xml放到layout-600*1024 这个文件中 就ok啦。 也可以和横竖屏结合这用 例如
layout-port-320*480 。你试试看,有问题hi我。