日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

解決Android Studio xml 格式化不自動換行的問題

瀏覽:262日期:2022-09-26 14:19:45

今天把Android Studio 2.3 更新為了3.0 遇到一個蛋疼的問題

如圖:

解決Android Studio xml 格式化不自動換行的問題

格式化完代碼后發現不會自動換行了,看著真心不爽。

后來發現其實是設置問題,如圖:

解決Android Studio xml 格式化不自動換行的問題

只要把這里打上√就可以了。

解決Android Studio xml 格式化不自動換行的問題

在此記錄一下,希望可以幫到后面的小伙伴

補充知識:Android實現控件內自動換行(比如LinearLayout內部實現子控件換行 )

一、創建類AntoLineUtil(換行操作主要在這里實現)

package com.inpor.fmctv.util;import android.content.Context;import android.content.res.TypedArray;import android.util.AttributeSet;import android.view.View;import android.view.ViewGroup;import com.inpor.fmctv.R;public class AntoLineUtil extends ViewGroup { /** * 子view左右間距 */ private int mHorizontalSpacing; /** * 子view上下行距離 */ private int mVerticalSpacing; private Context context; public AntoLineUtil(Context context) { this(context, null); this.context = context; } public AntoLineUtil(Context context, AttributeSet attrs) { this(context, attrs, 0); } public AntoLineUtil(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); if (attrs != null) { TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.AntoLineUtil); mHorizontalSpacing = array.getDimensionPixelOffset( R.styleable.AntoLineUtil_horizontalSpacing, 0); mVerticalSpacing = array.getDimensionPixelOffset( R.styleable.AntoLineUtil_verticalSpacing, 0); array.recycle(); if (mHorizontalSpacing < 0) mHorizontalSpacing = 0; if (mVerticalSpacing < 0) mVerticalSpacing = 0; } } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec); int count = getChildCount(); for (int i = 0; i < count; i++) { measureChild(getChildAt(i), widthMeasureSpec, heightMeasureSpec); } int widthMode = MeasureSpec.getMode(widthMeasureSpec); if (widthMode != MeasureSpec.EXACTLY) { widthMeasureSpec = MeasureSpec.makeMeasureSpec( getAutoLinefeedWidth(width), widthMode); } int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (heightMode != MeasureSpec.EXACTLY) { heightMeasureSpec = MeasureSpec.makeMeasureSpec( getAutoLinefeedHeight(width), heightMode); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } /** * 自動換行 計算需要的寬度 * * @param width 可用寬度 * @return 需要的寬度 */ private int getAutoLinefeedWidth(int width) { int totalWidth = getPaddingLeft() + getPaddingRight(); for (int i = 0; i < getChildCount(); i++) { if (i > 0) totalWidth += mHorizontalSpacing; View child = getChildAt(i); int childWidth = child.getMeasuredWidth(); totalWidth += childWidth; if (totalWidth >= width) {totalWidth = width;break; } } return totalWidth; } /** * 自動換行 計算需要的高度 * * @param width 可用寬度 * @return 需要的高度 */ private int getAutoLinefeedHeight(int width) { //一行最大可用寬度 int lineWidth = width - getPaddingLeft() - getPaddingRight(); //剩余可用寬度 int availableLineWidth = lineWidth; //需要的高度 int totalHeight = getPaddingTop() + getPaddingBottom(); int lineChildIndex = 0; //本行最大高度 int lineMaxHeight = 0; for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); int childWidth = child.getMeasuredWidth(); int childHeight = child.getMeasuredHeight(); //這個child需要的寬度 如果不是第一位的 那么需要加上間距 //這里是用來判斷需不需要換行 int needWidth = i == 0 ? childWidth : (childWidth + mHorizontalSpacing); //如果剩余可用寬度小于需要的長度 那么換行 if (availableLineWidth < needWidth) {totalHeight = totalHeight + lineMaxHeight;if (i > 0) totalHeight += mVerticalSpacing;availableLineWidth = lineWidth;lineMaxHeight = 0;lineChildIndex = 0; } //這個child需要的寬度 如果不是第一位的 那么需要加上間距 int realNeedWidth = lineChildIndex == 0 ? childWidth : (childWidth + mHorizontalSpacing); lineMaxHeight = Math.max(childHeight, lineMaxHeight); availableLineWidth = availableLineWidth - realNeedWidth; lineChildIndex++; } totalHeight = totalHeight + lineMaxHeight; return totalHeight; } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { layout(); } private void layout() { int count = getChildCount(); int childLeft = getPaddingLeft(); int childTop = getPaddingTop(); int lineWidth = getMeasuredWidth() - getPaddingRight() - getPaddingLeft(); int availableLineWidth = lineWidth; int lineChildIndex = 0; //一行的最大高度 int lineMaxHeight = 0; for (int i = 0; i < count; i++) { View child = getChildAt(i); int childWidth = child.getMeasuredWidth(); int childHeight = child.getMeasuredHeight(); int needWidth = i == 0 ? childWidth : (childWidth + mHorizontalSpacing); if (availableLineWidth < needWidth) {availableLineWidth = lineWidth;childTop += lineMaxHeight;if (i > 0) childTop += mVerticalSpacing;lineMaxHeight = 0;childLeft = getPaddingLeft();lineChildIndex = 0; } int realNeedWidth = lineChildIndex == 0 ? childWidth : (childWidth + mHorizontalSpacing); lineMaxHeight = Math.max(lineMaxHeight, childHeight); child.layout(childLeft + realNeedWidth - childWidth, childTop, childLeft + realNeedWidth, childTop + childHeight); availableLineWidth -= realNeedWidth; childLeft += realNeedWidth; lineChildIndex++; } } public int getHorizontalSpacing() { return mHorizontalSpacing; } public void setHorizontalSpacing(int horizontalSpacing) { mHorizontalSpacing = horizontalSpacing; } public int getVerticalSpacing() { return mVerticalSpacing; } public void setVerticalSpacing(int verticalSpacing) { mVerticalSpacing = verticalSpacing; }}

二、在values中的attrs.xml中添加以下代碼(實現子控件的邊距):

<declare-styleable name='AntoLineUtil'> <attr name='horizontalSpacing' format='dimension'/> <attr name='verticalSpacing' format='dimension'/> </declare-styleable>

三、添加固定的xml布局父控件,事先寫好,布局activity_video_preview.xml :

<com.inpor.fmctv.util.AntoLineUtil android: android:layout_width='@dimen/size_dp_630' android:layout_height='@dimen/size_dp_138' android:layout_marginTop='@dimen/size_dp_18' android:orientation='horizontal' app:horizontalSpacing='@dimen/size_dp_18' app:verticalSpacing='@dimen/size_dp_18'></com.inpor.fmctv.util.AntoLineUtil>

四、添加固定的xml布局子控件,事先寫好,動態添加進去,布局item_camera_info.xml :

<?xml version='1.0' encoding='utf-8'?><LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' android: android:layout_width='@dimen/size_dp_198' android:layout_height='@dimen/size_dp_60' android:orientation='horizontal' android:paddingLeft='@dimen/size_dp_18' android:paddingRight='@dimen/size_dp_18' android:gravity='center_vertical' android:background='@color/textcolor_395878'> <TextView android: android:layout_width='@dimen/size_dp_120' android:layout_height='wrap_content' android:textSize='@dimen/size_sp_24' android:textColor='@color/white'/> <CheckBox android: android:layout_width='@dimen/size_dp_24' android:layout_height='@dimen/size_dp_24' android:button='@null' android:background='@drawable/radio_button_select_ico' /></LinearLayout>

五、在其他方法中動態添加子控件:

AntoLineUtil cameraGroup = (AntoLineUitl) findViewById(R.id.camera_group); // 此處是找到父控件LinearLayoutfor (int i = 0; i<6; i++) { // 用以下方法將layout布局文件換成view LayoutInflater inflater = getLayoutInflater(); View view = inflater.inflate(R.layout.item_camera_info,null); TextView textView = view.findViewById(R.id.video_preview_item_tv); textView.setText('攝像頭'+ (cameraId+1)); cameraGroup.addView(view);}

六、效果圖:

解決Android Studio xml 格式化不自動換行的問題

以上這篇解決Android Studio xml 格式化不自動換行的問題就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
亚洲青青久久| 蜜桃久久久久久| 亚洲免费播放| 精品丝袜在线| 国产日产一区| 黑人精品一区| 久久久免费人体| 少妇精品久久久一区二区| 99久久视频| 视频二区不卡| 成人综合一区| 卡一卡二国产精品| 日韩国产欧美在线播放| 中文在线不卡| 亚洲永久字幕| 人人精品亚洲| 精品免费在线| 久久尤物视频| 日本精品另类| 欧美日韩一区二区国产| 日韩视频精品在线观看| 视频小说一区二区| 亚洲成人不卡| 91九色精品| 91成人精品视频| 99在线|亚洲一区二区| 黄色日韩在线| 亚洲精品一二| 中文字幕av一区二区三区人| 日韩在线一区二区| 日本不卡视频在线观看| 一区二区三区国产盗摄| 日韩精品91亚洲二区在线观看| 日本综合字幕| 高清精品久久| 日韩欧美字幕| 日韩中文字幕区一区有砖一区| 日本不卡一区二区| 国产精品久久久久久久久久白浆 | 中文av在线全新| 欧美a级一区| 青青国产精品| 国产va免费精品观看精品视频| 91偷拍一区二区三区精品| 电影天堂国产精品| 亚洲欧美日韩专区| 国产欧美69| 欧美精品羞羞答答| 国产探花一区在线观看| 91精品精品| 久久国产精品色av免费看| 久久精品国产精品亚洲毛片| 久久精品av麻豆的观看方式| 精品一区二区男人吃奶| 亚洲欧美日韩在线观看a三区| 国产日韩免费| 一区在线免费观看| 国产精品超碰| 日韩免费高清| 国产精品亲子伦av一区二区三区| 免费的成人av| 日韩1区2区日韩1区2区| 国内亚洲精品| 九九久久国产| 中文无码日韩欧| 国产一区二区三区视频在线| 日韩有吗在线观看| 激情视频一区二区三区| 欧美韩日一区| 国产精品黄网站| 伊人久久一区| 日韩一级网站| 国精品产品一区| 国产精品久久久久久久久久白浆| 在线国产精品一区| 亚洲天堂黄色| 精品日韩视频| 亚洲三级欧美| 精精国产xxxx视频在线野外| 久久99久久久精品欧美| 久久激情五月激情| 国产亚洲欧美日韩精品一区二区三区 | 国产亚洲一区二区三区不卡| 影视先锋久久| 免费在线小视频| 中文字幕在线看片| 成人羞羞视频播放网站| 久久高清免费| 亚洲欧美日韩高清在线| 伊人影院久久| 亚洲久久在线| 欧美日韩va| 精品黄色一级片| 韩国久久久久久| 欧美69视频| 亚洲尤物在线| 欧美亚洲综合视频| 精品亚洲a∨| 精品黄色一级片| 成人日韩在线观看| 亚洲深深色噜噜狠狠爱网站| 奇米色欧美一区二区三区| 久久精品国产成人一区二区三区| 日本久久成人网| 综合激情一区| 国产成人精品一区二区三区免费 | 亚洲毛片视频| 国产福利资源一区| 麻豆一区二区在线| 99成人在线| 久久av资源| 久久精品99久久无色码中文字幕| 一本一道久久a久久| 久久伊人亚洲| 男人的天堂久久精品| 麻豆精品视频在线观看| 国产国产精品| 国产成人精品一区二区免费看京| 亚洲欧美日韩专区| 日韩在线二区| 国产精品久久久久久av公交车| 91久久久精品国产| 国语精品一区| 99在线|亚洲一区二区| 久久精品国产久精国产| 日韩一区二区三区免费视频| 日韩欧美激情| 日韩精品久久久久久久电影99爱| 综合激情网...| 精品国产黄a∨片高清在线| 亚洲成人免费| 秋霞影视一区二区三区| 欧美xxxx性| 日韩国产精品久久久久久亚洲| 国产韩日影视精品| 精品国产亚洲一区二区三区| 蜜臀精品久久久久久蜜臀| 久久久久一区| 久久xxx视频| 国产亚洲高清在线观看| 日本精品另类| 日本不卡在线视频| 日韩一区精品| 天堂俺去俺来也www久久婷婷| 99成人在线视频| 秋霞影视一区二区三区| 日韩影院二区| 不卡在线一区| 免费人成黄页网站在线一区二区| 五月综合激情| 国产九九精品| 高清不卡亚洲| 99国产精品| 少妇精品久久久| 7m精品国产导航在线| 精品国产亚洲一区二区三区在线| 福利在线免费视频| 欧美手机在线| 蜜臀av一区二区在线免费观看| 欧美一区成人| 国产精品久久久久蜜臀| 欧美99久久| 婷婷成人基地| 亚洲欧美一级| 久久精品一区二区国产| 精品三级久久| 999国产精品永久免费视频app| 中文在线一区| 91成人网在线观看| 日本视频在线一区| 欧美国产免费| 色婷婷久久久| 亚洲免费专区| 久久精品一区二区国产| 日韩在线第七页| 欧美精品国产| 久久久久91| 日韩一区二区三区四区五区| 欧美日韩视频免费看| 美女亚洲一区| 日韩av一区二区三区| 精品视频一区二区三区在线观看| 夜夜嗨av一区二区三区网站四季av| 亚洲一区二区三区免费在线观看| 久久国产99| 国产精品成人自拍| 蜜桃视频一区二区三区| 麻豆精品视频在线| 亚洲一区二区三区免费在线观看| 久久国产精品亚洲77777| 黄色aa久久| 亚洲69av| 精品在线播放| 一本大道色婷婷在线| 日韩高清一区| 亚洲福利一区| 国产精品精品| 日本а中文在线天堂| 日韩国产一二三区| 国产一区二区三区探花|