Android Studio 3.5格式化布局代碼時(shí)錯(cuò)位、錯(cuò)亂bug的解決
更新到3.5版本后,格式化布局文件代碼,會(huì)自動(dòng)給排序元素,導(dǎo)致界面布局錯(cuò)亂
解決辦法:
設(shè)置 > code style > XML 右上角 Set from然后選擇Predefined Style...>Android即可

補(bǔ)充知識(shí):Android Studio:Reformat Code格式化Xml布局代碼后控件順序錯(cuò)亂
Android Studio升級(jí)3.5之后,遇到個(gè)奇葩問(wèn)題,在布局xml文件中格式化代碼后,控件的順序都變了,這不是我們想要的結(jié)果,網(wǎng)上搜了一下,確實(shí)是AS3.5的鍋,每次升級(jí)都會(huì)遇到不同的問(wèn)題,先記錄一下吧,以后有時(shí)間再研究為什么做的調(diào)整。
<?xml version='1.0' encoding='utf-8'?><LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:tools='http://schemas.android.com/tools' android:layout_width='match_parent' android:layout_height='match_parent' android:orientation='vertical' android:padding='16dp' tools:context='sun.geoffery.mvpdemo.MainActivity'> <TextView android: android:layout_width='match_parent' android:layout_height='0dp' android:layout_weight='1' android:text='點(diǎn)擊按鈕獲取網(wǎng)絡(luò)數(shù)據(jù)' /> <Button android: android:layout_width='match_parent' android:layout_height='wrap_content' android:text='獲取數(shù)據(jù)【成功】' /> <Button android: android:layout_width='match_parent' android:layout_height='wrap_content' android:text='獲取數(shù)據(jù)【失敗】' /> <Button android: android:layout_width='match_parent' android:layout_height='wrap_content' android:text='獲取數(shù)據(jù)【異常】' /></LinearLayout>
這個(gè)簡(jiǎn)單的布局界面大致如下圖所示:

走你,Ctrl+Shift+F,格式化一把,再看我們的代碼:
<?xml version='1.0' encoding='utf-8'?><LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:tools='http://schemas.android.com/tools' android:layout_width='match_parent' android:layout_height='match_parent' android:orientation='vertical' android:padding='16dp' tools:context='sun.geoffery.mvpdemo.MainActivity'> <Button android: android:layout_width='match_parent' android:layout_height='wrap_content' android:text='獲取數(shù)據(jù)【成功】' /> <Button android: android:layout_width='match_parent' android:layout_height='wrap_content' android:text='獲取數(shù)據(jù)【失敗】' /> <Button android: android:layout_width='match_parent' android:layout_height='wrap_content' android:text='獲取數(shù)據(jù)【異常】' /> <TextView android: android:layout_width='match_parent' android:layout_height='0dp' android:layout_weight='1' android:text='點(diǎn)擊按鈕獲取網(wǎng)絡(luò)數(shù)據(jù)' /></LinearLayout>
原本最頂部的TextView被格式化到了最下面,一臉懵逼,界面如下:

具體解決方法如下:
Settings?>Editor?> Code Style?>XML
點(diǎn)擊右上角的Set from->Predefined Style選擇Android后點(diǎn)擊OK保存,Perfect!

再格式化代碼,就是我們想要的效果了

以上這篇Android Studio 3.5格式化布局代碼時(shí)錯(cuò)位、錯(cuò)亂bug的解決就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. JSP+Servlet實(shí)現(xiàn)文件上傳到服務(wù)器功能2. ASP中實(shí)現(xiàn)字符部位類似.NET里String對(duì)象的PadLeft和PadRight函數(shù)3. php使用正則驗(yàn)證密碼字段的復(fù)雜強(qiáng)度原理詳細(xì)講解 原創(chuàng)4. CSS可以做的幾個(gè)令你嘆為觀止的實(shí)例分享5. 利用CSS3新特性創(chuàng)建透明邊框三角6. vue前端RSA加密java后端解密的方法實(shí)現(xiàn)7. 解析原生JS getComputedStyle8. 淺談?dòng)蓀osition屬性引申的css進(jìn)階討論9. ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)經(jīng)驗(yàn)分享10. Jsp中request的3個(gè)基礎(chǔ)實(shí)踐

網(wǎng)公網(wǎng)安備