当前位置:首页 » 编程软件 » 安卓编程换行

安卓编程换行

发布时间: 2022-09-08 20:06:07

A. 安卓怎么在string的特定的位置前面加换行

换行: <string name="hello_world">你好!\n世界!</string> 其中的\n就代表换行
空格: <string name="out_bound_submit">出 库</string> 其中的 就代表空格
缩进: <string name="hello_world">你好!\t世界!</string> 其中的\t就代表按一次Tab键的几个空格

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

C. 安卓开发AlertDialog里面的Message怎么换行

你的换行符是在字符串的首尾还是中间的?如果是首尾就可以用str.trim()去掉 如果不是你得想其他方式。 TextView v = (TextView )super.findViewById(R.id.‘TextView的id号’); v.setText(str.trim());

D. 用android平板电脑编python程序怎么换行

可以,但不能写原生程序,需要安装sl4a后,再里面安装python脚本。 可以,很多动态语言都支持 安卓程序不是用java写吗 安卓Android2.2,为,yhlvwZ

E. 求解在安卓开发中,如何换行,/n完全无效

应该是\n,你那个斜杠反了
<TextView
android:layout_height="wrap_content"
android:text="1\n2"
android:layout_width="wrap_content"
android:textSize="20sp"/>
这样就行了

F. 在手机上通过termyx使用Python编程,如何换行,我按下回车键后直接显示错误

1、在python中,Python 用反斜线 (“”) 作为续行符(换行符),这里以python3.5为例。首先运行终端或者cmd命令行(windows下),执行python3.5的命令。

G. android textview 怎么换行

textView如果想要强制换行的话,必须先把TextView显示方式修改为多行(android:singleLine="false"),然后才能换行。
方法一般用两种:

1、在字符串里加入“ ”,如"abc rc";

2、把TextView设置为固定宽度,然后让系统自动换行。如android:layout_width="100dp";

(7)安卓编程换行扩展阅读

Class Overview

向用户显示文本,并可选择允许他们编辑文本。TextView是一个完整的文本编辑器,但是基类为不允许编辑;其子类EditText允许文本编辑。

允许用户复制部分或全部内容,将其粘贴到别的地方,设置XML属性Android:textisselectable :“真” 或设置相关方法 settextisselectable 为“真”。textisselectable flag 允许用户在TextView选择手势,从而触发系统内置的复制/粘贴控件。

Displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing; seeEditTextfor a subclass that configures the text view for editing.

To allow users to some or all of the TextView's value and paste it somewhere else, set the XML attributeandroid:textIsSelectableto "true" or callsetTextIsSelectable(true). ThetextIsSelectableflag allows users to make selection gestures in the TextView, which in turn triggers the system's built-in /paste controls.

H. toast 中的信息怎么分两行显示(android开发),急!!!!

最简单的方法只有一个。在显示信息中通过 进行换行

示例代码

Stringmsg="第一行
第二行";//通过
换行
toast=Toast.makeText(Activity.this,msg,Toast.LENGTH_LONG);//显示信息

I. android怎么让一段长的代码自动换行

android开发使用的是eclipse或者android studio,内置的一个快捷键:ctrl+shift+F,可以自动变换格式,一些长得代码就会自动换行。
android开发工具会提供很多快捷键,比如alt+方向键实现移动代码等等。

J. 手机如何换行

手机在用键盘打字的时候换换行,一般都是用那个有一个箭头的键。点一下它就会换行相当于键盘上的enter键。

热点内容
河南电脑服务器托管云主机 发布:2025-03-24 07:10:36 浏览:470
收件服务器应该是什么 发布:2025-03-24 06:52:37 浏览:873
小黄狗编程 发布:2025-03-24 06:43:02 浏览:639
华为手机手画密码如何设置 发布:2025-03-24 06:40:20 浏览:658
读java源码 发布:2025-03-24 06:29:06 浏览:35
欧皇源码 发布:2025-03-24 06:26:18 浏览:858
为什么id密码在异地登录 发布:2025-03-24 06:17:13 浏览:46
google地图连接服务器地址 发布:2025-03-24 06:12:43 浏览:359
安卓怎么样恢复手机删除的视频 发布:2025-03-24 06:07:03 浏览:133
格式化手机usb存储器 发布:2025-03-24 05:52:33 浏览:238