安卓編程換行
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鍵。