当前位置:首页 » 安卓系统 » android控件换行

android控件换行

发布时间: 2023-02-21 01:50:01

‘壹’ 请问在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】

希望能够帮到你

‘贰’ 安卓手机打字怎么换行

安卓手机打字换行的方法:

1、首先打开安卓手机的主界面;

2、再打开需要输入文字的页面;

3、在页面中点击输入框,出现输入法以后开始打字;

4、选择最右下角的“换行键”或者“回车键”,点击即可换行。



文字输入是安卓手机的一项基本操作功能,在使用安卓手机打字时,根据具体需要,可以对文字进行换行输入,首先解锁安卓手机的主界面,确保接下来的正常操作;在手机中打开编辑文字的软件,点击进入;在输入文字界面中点击输入框,会出现虚拟键盘的相关界面;在该界面上,选择最右下角的回车键图标即可,有的输入法会直接出现换行,点击即可。

需要注意的是安卓手机在输入文字的时候或在消息输入窗口,突然没有反应,或无法弹出输入法键盘,从而无法输入,这类情况有可能是输入法无响应,即运行不顺畅卡死,需要耐心等待或关闭后重新启动。

‘叁’ 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 LinearLayout 里面的东西怎么换行

由于前段时间项目中使用到了自动换行的线性布局,本来打算用表格布局在里面一个个的用Java代码添加ImageView的,但是添加的View控件是不确定的,因为得靠服务器的数据返回,就这样手动用Java代码画布局的方式就这样夭折了,因为在表哥布局中我无法确定一行显示多少个ImageView的数目,所以无法动态添加,最后自能自己去看看那种能够换行的线性布局了,线性布局比较不好的是不能自动换行,也就是当设置LinearLayout的orentation 设置为vertical 为竖直方向也就是只有一列,每行只能显示一个View或者View的子类,当设置LinearLayout的orentitation为Horizontal,LinearLayout的只能显示为一行,横向显示,当屏幕满了的时候,View控件并不会自动换行,所以我们要做的就是在LinearLayout满的时候自动换行。x0dx0a需要了解的是怎么样绘制根据子控件的长宽绘制父控件的宽度与高度,所以需要传入的参数控件的高度,视图分为两种一种是View类型的,代表控件有TextView,Button,EditText 等等,还有一种是装视图的容器控件继承自ViewGroup的控件,如LinearLayout,RelativeLayout,TabHost等等控件,需要自动换行的线性布局的话,就需要根据子控件的高度与宽度,来动态加载父控件的高度与宽度,所以需要在构造函数中传入每一个子控件的固定的高度,或者是动态设置子控件的高度与宽度。x0dx0a将自定义的LinearLayout 也继承自ViewGroup 并且重写抽象类ViewGrouop的几个方法:onMeasure(),onLayout(),dispathDraw() 三个方法的意思分别是:第一个onMeasure()是用来计算控件以及子控件所占用的区域,第二个onLayout()是控制子控件的换行,第三个可写可不写,主要是用来绘制控件的边框,x0dx0a自定义LinearLayout的代码如下:x0dx0ax0dx0a[java] view plainprint?x0dx0apackage com.huanglong.mylinearlayout; x0dx0a x0dx0aimport android.content.Context; x0dx0aimport android.graphics.Canvas; x0dx0aimport android.graphics.Color; x0dx0aimport android.graphics.Paint; x0dx0aimport android.graphics.Rect; x0dx0aimport android.util.AttributeSet; x0dx0aimport android.view.View; x0dx0aimport android.view.ViewGroup; x0dx0a x0dx0a/** x0dx0a * @author huanglong 2013-5-28 自定义自动换行LinearLayout x0dx0a */ x0dx0apublic class FixGridLayout extends ViewGroup { x0dx0a private int mCellWidth; x0dx0a private int mCellHeight; x0dx0a x0dx0a public FixGridLayout(Context context) { x0dx0a super(context); x0dx0a } x0dx0a x0dx0a public FixGridLayout(Context context, AttributeSet attrs) { x0dx0a super(context, attrs); x0dx0a } x0dx0a x0dx0a public FixGridLayout(Context context, AttributeSet attrs, int defStyle) { x0dx0a super(context, attrs, defStyle); x0dx0a } x0dx0a x0dx0a public void setmCellWidth(int w) { x0dx0a mCellWidth = w; x0dx0a requestLayout(); x0dx0a } x0dx0a x0dx0a public void setmCellHeight(int h) { x0dx0a mCellHeight = h; x0dx0a requestLayout(); x0dx0a } x0dx0a x0dx0a /** x0dx0a * 控制子控件的换行 x0dx0a */ x0dx0a @Override x0dx0a protected void onLayout(boolean changed, int l, int t, int r, int b) { x0dx0a int cellWidth = mCellWidth; x0dx0a int cellHeight = mCellHeight; x0dx0a int columns = (r - l) / cellWidth; x0dx0a if (columns < 0) { x0dx0a columns = 1; x0dx0a } x0dx0a int x = 0; x0dx0a int y = 0; x0dx0a int i = 0; x0dx0a int count = getChildCount(); x0dx0a for (int j = 0; j < count; j++) { x0dx0a final View childView = getChildAt(j); x0dx0a // 获取子控件Child的宽高 x0dx0a int w = childView.getMeasuredWidth(); x0dx0a int h = childView.getMeasuredHeight(); x0dx0a // 计算子控件的顶点坐标 x0dx0a int left = x + ((cellWidth - w) / 2); x0dx0a int top = y + ((cellHeight - h) / 2); x0dx0a // int left = x; x0dx0a // int top = y; x0dx0a // 布局子控件 x0dx0a childView.layout(left, top, left + w, top + h); x0dx0a x0dx0a if (i >= (columns - 1)) { x0dx0a i = 0; x0dx0a x = 0; x0dx0a y += cellHeight; x0dx0a } else { x0dx0a i++; x0dx0a x += cellWidth; x0dx0a x0dx0a } x0dx0a } x0dx0a } x0dx0a x0dx0a /** x0dx0a * 计算控件及子控件所占区域 x0dx0a */ x0dx0a @Override x0dx0a protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { x0dx0a // 创建测量参数 x0dx0a int cellWidthSpec = MeasureSpec.makeMeasureSpec(mCellWidth, MeasureSpec.AT_MOST); x0dx0a int cellHeightSpec = MeasureSpec.makeMeasureSpec(mCellHeight, MeasureSpec.AT_MOST); x0dx0a // 记录ViewGroup中Child的总个数 x0dx0a int count = getChildCount(); x0dx0a // 设置子空间Child的宽高 x0dx0a for (int i = 0; i < count; i++) { x0dx0a View childView = getChildAt(i); x0dx0a /* x0dx0a * 090 This is called to find out how big a view should be. 091 The x0dx0a * parent supplies constraint information in the width and height x0dx0a * parameters. 092 The actual mesurement work of a view is performed x0dx0a * in onMeasure(int, int), 093 called by this method. 094 Therefore, x0dx0a * only onMeasure(int, int) can and must be overriden by subclasses. x0dx0a * 095 x0dx0a */ x0dx0a childView.measure(cellWidthSpec, cellHeightSpec); x0dx0a } x0dx0a // 设置容器控件所占区域大小 x0dx0a // 注意setMeasuredDimension和resolveSize的用法 x0dx0a setMeasuredDimension(resolveSize(mCellWidth * count, widthMeasureSpec), x0dx0a resolveSize(mCellHeight * count, heightMeasureSpec)); x0dx0a // setMeasuredDimension(widthMeasureSpec, heightMeasureSpec); x0dx0a x0dx0a // 不需要调用父类的方法 x0dx0a // super.onMeasure(widthMeasureSpec, heightMeasureSpec); x0dx0a } x0dx0a x0dx0a /** x0dx0a * 为控件添加边框 x0dx0a */ x0dx0a @Override x0dx0a protected void dispatchDraw(Canvas canvas) { x0dx0a // 获取布局控件宽高 x0dx0a int width = getWidth(); x0dx0a int height = getHeight(); x0dx0a // 创建画笔 x0dx0a Paint mPaint = new Paint(); x0dx0a // 设置画笔的各个属性 x0dx0a mPaint.setColor(Color.BLUE); x0dx0a mPaint.setStyle(Paint.Style.STROKE); x0dx0a mPaint.setStrokeWidth(10); x0dx0a mPaint.setAntiAlias(true); x0dx0a // 创建矩形框 x0dx0a Rect mRect = new Rect(0, 0, width, height); x0dx0a // 绘制边框 x0dx0a canvas.drawRect(mRect, mPaint); x0dx0a // 最后必须调用父类的方法 x0dx0a super.dispatchDraw(canvas); x0dx0a } x0dx0a x0dx0a} x0dx0a然后在Xml文件中引用自己定义的控件,在Java代码中调用:x0dx0ax0dx0a[java] view plainprint?x0dx0apackage com.huanglong.mylinearlayout; x0dx0a x0dx0aimport android.os.Bundle; x0dx0aimport android.app.Activity; x0dx0aimport android.view.Menu; x0dx0aimport android.view.MenuItem; x0dx0aimport android.widget.CheckBox; x0dx0aimport android.widget.SimpleAdapter; x0dx0aimport android.support.v4.app.NavUtils; x0dx0a x0dx0apublic class MainActivity extends Activity { x0dx0a private SimpleAdapter adapter; x0dx0a @Override x0dx0a public void onCreate(Bundle savedInstanceState) { x0dx0a super.onCreate(savedInstanceState); x0dx0a setContentView(R.layout.activity_main); x0dx0a FixGridLayout fixGridLayout = (FixGridLayout) findViewById(R.id.ll); x0dx0a fixGridLayout.setmCellHeight(30); x0dx0a fixGridLayout.setmCellWidth(100); x0dx0a for (int i = 0; i < 7; i++) { x0dx0a CheckBox box = new CheckBox(MainActivity.this); x0dx0a box.setText("第"+i+"个"); x0dx0a fixGridLayout.addView(box); x0dx0a } x0dx0a } x0dx0a x0dx0a @Override x0dx0a public boolean onCreateOptionsMenu(Menu menu) { x0dx0a getMenuInflater().inflate(R.menu.activity_main, menu); x0dx0a return true; x0dx0a } x0dx0ax0dx0a}

‘伍’ android 中多个TextView放在一个LinearLayout中,请问如何将TextView中的文字自动换行或者修改布局实现

首先TextView的height设置成wrapcontent
其次TextView的singleLine属性不设置

‘陆’ Android 实现 EditText 文本自动换行

很简单,在布局 XML 文件的 EditText 中加上下面这行:
android:inputType="textMultiLine"

即可。

‘柒’ 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.将数据分别填充到左右两个控件中
这应该算是自动换行经典实例了吧,相信这个搞定以后同类型的需求都不成问题了。

热点内容
少女前线防检测脚本 发布:2025-05-16 08:59:07 浏览:726
编译器对系统的依赖 发布:2025-05-16 08:37:29 浏览:710
javamap数组 发布:2025-05-16 08:37:28 浏览:450
移动光猫如何自行修改密码 发布:2025-05-16 08:20:15 浏览:124
作为基线存储 发布:2025-05-16 08:15:22 浏览:858
安卓怎么关闭手机应用推荐 发布:2025-05-16 08:03:38 浏览:929
sql内置函数 发布:2025-05-16 08:03:34 浏览:922
怎么看服务器内存型号 发布:2025-05-16 08:03:30 浏览:812
哪里修安卓手机最好 发布:2025-05-16 07:58:25 浏览:825
服务器和电脑是什么区别 发布:2025-05-16 07:58:24 浏览:720