當前位置:首頁 » 安卓系統 » android布局換行

android布局換行

發布時間: 2022-07-03 10:10:05

⑴ 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我。

熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:637
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:366
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:82
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:308
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:789
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:339
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:210
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:810
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:364
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:590