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:id="@+id/text" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:text="點(diǎn)擊按鈕獲取網(wǎng)絡(luò)數(shù)據(jù)" /> <Button android:id="@+id/getData" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="獲取數(shù)據(jù)【成功】" /> <Button android:id="@+id/getDataForFailure" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="獲取數(shù)據(jù)【失敗】" /> <Button android:id="@+id/getDataForError" 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:id="@+id/getData" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="獲取數(shù)據(jù)【成功】" /> <Button android:id="@+id/getDataForFailure" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="獲取數(shù)據(jù)【失敗】" /> <Button android:id="@+id/getDataForError" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="獲取數(shù)據(jù)【異?!? /> <TextView android:id="@+id/text" 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è)參考,也希望大家多多支持腳本之家。
- android studio實(shí)現(xiàn)簡(jiǎn)單的計(jì)算器(無(wú)bug)
- Android Studio debug.keystore位置介紹
- 解決android設(shè)備斷電重啟后WIFI不能自動(dòng)重連的BUG(收藏)
- 關(guān)于ADB的Android Debug Bridge(安卓調(diào)試橋)那些事
- Android同時(shí)安裝Release和Debug版本的方法
- Android Studio 自定義Debug變量視圖的方法
- Android Studio之Debug運(yùn)行期代碼植入的方法
- Android Studio中debug功能詳解
- Android實(shí)現(xiàn)錄音方法(仿微信語(yǔ)音、麥克風(fēng)錄音、發(fā)送語(yǔ)音、解決5.0以上BUG)
- 淺談Android Studio如何Debug對(duì)應(yīng)so文件C/C++代碼
- Android Studio 報(bào)錯(cuò)“app:processDebugResources"解決方法
- Android 判斷是開發(fā)debug模式,還是發(fā)布release模式的方法
- Android 開發(fā) 使用WebUploader解決安卓微信瀏覽器上傳圖片中遇到的bug
- Android 常見(jiàn)bug匯總及解決方案
相關(guān)文章
Android仿小米安全中心檢測(cè)進(jìn)度條效果
這篇文章主要介紹了Android仿小米安全中心檢測(cè)進(jìn)度條效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10Android APK優(yōu)化工具Zipalign詳解
本文主要介紹Android APK優(yōu)化工具Zipalign,這里整理了相關(guān)資料,并詳細(xì)介紹如何使用Zipalign工具及使用技巧,有需要的小伙伴可以參考下2016-09-09Android編程之Application設(shè)置全局變量及傳值用法實(shí)例分析
這篇文章主要介紹了Android編程之Application設(shè)置全局變量及傳值用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了全局變量及傳值的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-12-12Android 側(cè)滑抽屜菜單的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android 側(cè)滑抽屜菜單的實(shí)現(xiàn)代碼,本文通過(guò)實(shí)例圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03Android開發(fā)簽名知識(shí)梳理總結(jié)
這篇文章主要介紹了Android開發(fā)簽名知識(shí)梳理總結(jié),Android?系統(tǒng)要求所有?APK?必須先使用證書進(jìn)行數(shù)字簽名,然后才能安裝到設(shè)備上進(jìn)行更新2022-06-06Android實(shí)現(xiàn)錄音功能實(shí)現(xiàn)實(shí)例(MediaRecorder)
本篇文章主要介紹了Android實(shí)現(xiàn)錄音的實(shí)例代碼(MediaRecorder),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07神經(jīng)網(wǎng)絡(luò)API、Kotlin支持,那些你必須知道的Android 8.1預(yù)覽版和Android Studio 3.0新特
這篇文章主要介紹了神經(jīng)網(wǎng)絡(luò)API、Kotlin支持,那些你必須了解的Android 8.1預(yù)覽版和Android Studio 3.0新特性,需要的朋友可以參考下2017-10-10