Android Studio 3.5格式化布局代码时错位、错乱bug的解决
2020-03-18 12:09
736 查看
更新到3.5版本后,格式化布局文件代码,会自动给排序元素,导致界面布局错乱
解决办法:
设置 > code style > XML 右上角 Set from然后选择Predefined Style...>Android即可
补充知识:Android Studio:Reformat Code格式化Xml布局代码后控件顺序错乱
Android Studio升级3.5之后,遇到个奇葩问题,在布局xml文件中格式化代码后,控件的顺序都变了,这不是我们想要的结果,网上搜了一下,确实是AS3.5的锅,每次升级都会遇到不同的问题,先记录一下吧,以后有时间再研究为什么做的调整。
<?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="点击按钮获取网络数据" /> <Button android:id="@+id/getData" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="获取数据【成功】" /> <Button android:id="@+id/getDataForFailure" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="获取数据【失败】" /> <Button android:id="@+id/getDataForError" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="获取数据【异常】" /> </LinearLayout>
这个简单的布局界面大致如下图所示:
走你,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="获取数据【成功】" /> <Button android:id="@+id/getDataForFailure" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="获取数据【失败】" /> <Button android:id="@+id/getDataForError" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="获取数据【异常】" /> <TextView android:id="@+id/text" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:text="点击按钮获取网络数据" /> </LinearLayout>
原本最顶部的TextView被格式化到了最下面,一脸懵逼,界面如下:
具体解决方法如下:
Settings–>Editor–> Code Style–>XML
点击右上角的Set from->Predefined Style选择Android后点击OK保存,Perfect!
再格式化代码,就是我们想要的效果了
以上这篇Android Studio 3.5格式化布局代码时错位、错乱bug的解决就是小编分享给大家的全部内容了,希望能给大家一个参考
您可能感兴趣的文章:
相关文章推荐
- 解决RelativeLayout中 gone之后的布局错位问题。RelativeLayout的alignWithParentIfMissing
- swift 代码提示和文档查看失效 bug解决 (ios 8)
- Android Studio 不自动弹起代码提示功能解决办法 do not auto popup code completion
- Android Studio如何使用Git提交代码到GitHub和OsChina并解决冲突
- 代码片段--Button抢焦点, 无论点在哪都是button触发. 解决方法很简单, 在item最外层的布局中加一个配置:
- Android studio 升级3.0 出现“无法解决依赖”bug
- android设计的布局在阿拉伯语下界面错乱的解决方法
- 将欧阳老师写的疯狂连连看的代码移植到android studio的一些问题解决方法
- 一句代码就解决一个开发中常见的小bug....
- 解决系统切换字号,app内的文字变化导致布局错乱
- 解决android studio 利用git向github上传代码时遇到的Can’t finish GitHub sharing process Successfully created projec
- mac下解决android studio补全代码和自动提示问题
- 解决Android studio2.2版本之后默认扁平化布局问题
- Android Studio 界面布局之xml文件中给输入框editText修改下划线颜色 / 为按钮设置圆角和颜色 / 约束布局预览效果和运行效果不一致 问题的解决
- IE6的双倍,3px,注释引起的文字错位等几个BUG解决方法
- Android Studio 布局文件格式化代码
- hge版《见习小恶魔》源代码中新发现的bug和解决方法以及解决vista兼容性问题
- 引入别人的Android Studio项目遇到的bug以及解决方法
- android studio布局文件/XML怎么代码补全
- 解决Win10+Unity+VSCode无法代码补全的bug