當前位置:首頁 » 安卓系統 » 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、打開微信中的一個對話框,點擊下面的輸入欄進行文字的輸入:

熱點內容
安卓界面如何變成蘋果手機界面 發布:2024-03-28 18:07:17 瀏覽:741
方舟手游如何卡安卓大廳會員 發布:2024-03-28 17:52:37 瀏覽:240
空域銳化演算法 發布:2024-03-28 17:52:32 瀏覽:499
虎牙安卓版是什麼意思 發布:2024-03-28 17:43:10 瀏覽:859
電腦改成雲伺服器 發布:2024-03-28 17:37:50 瀏覽:265
文件夾審計 發布:2024-03-28 17:08:20 瀏覽:241
密碼反編譯是什麼意思 發布:2024-03-28 17:02:54 瀏覽:309
linux下samba 發布:2024-03-28 16:54:12 瀏覽:539
我的世界國際服手機版免費開伺服器 發布:2024-03-28 16:45:36 瀏覽:284
phpmongodb擴展下載 發布:2024-03-28 16:41:03 瀏覽:323