AndroidStudio界面布局
用惯了VisualStudio这AndroidStudio真是不习惯。个人感觉VisualStudio是一个严格按照面向对象思想制作的集成化、所见即所得的开发工具。而AndroidStudio则是一个大杂烩。就界面布局来说VS的布局是由容器控件的位置属性来构成是面向对象的。使用简洁明了。AndroidStudio的布局就是想啥来啥虽然也有可视化的设计器但设计器里托拽下的位置居然仅供设计参考用运行时无效。必需专门给控件添加布局参数。AndroidStudio默认布局方式为ConstraintLayout布局我认为引导线定位是一个兼容性较好的定位方式。用法示例app:layout_constraintTop_toTopOfid/V1app:layout_constraintBottom_toBottomOfid/V1V1是条水平引导线如果只有第一行Top_toTop表示控件顶部位于引导线下方。如果两行都有表示控件对于引导线垂直居中。androidx.constraintlayout.widget.ConstraintLayout android:layout_widthmatch_parent android:layout_heightmatch_parent !-- 垂直 Guideline距左侧 100dp -- androidx.constraintlayout.widget.Guideline android:idid/v1 android:layout_widthwrap_content android:layout_heightwrap_content android:orientationvertical app:layout_constraintGuide_begin100dp / !-- 垂直引导线位于屏幕宽度 30% 处 -- androidx.constraintlayout.widget.Guideline android:idid/guideline_30 android:layout_widthwrap_content android:layout_heightwrap_content android:orientationvertical app:layout_constraintGuide_percent0.3 / !-- 水平引导线位于屏幕高度 61.8% 处 (黄金分割) -- androidx.constraintlayout.widget.Guideline android:idid/guideline_golden android:layout_widthwrap_content android:layout_heightwrap_content android:orientationhorizontal app:layout_constraintGuide_percent0.618 / !-- 水平引导线居中 -- androidx.constraintlayout.widget.Guideline android:idid/h1 android:layout_widthwrap_content android:layout_heightwrap_content android:orientationhorizontal app:layout_constraintGuide_percent0.5 / Button android:idid/button android:layout_widthwrap_content !-- Button的大小将根据其内容自动调整-- android:layout_heightwrap_content android:textClick Me app:layout_constraintStart_toStartOfid/guideline !-- 对于垂直引导线 -- app:layout_constraintEnd_toEndOfid/guideline !-- 对于垂直引导线 -- app:layout_constraintTop_toTopOfparent !-- 或者其他合适的顶部约束 -- app:layout_constraintBottom_toBottomOfparent / !-- 或者其他合适的底部约束 -- Button android:idid/button1 android:layout_width100dp android:layout_height20dp app:layout_constraintBottom_toTopOfid/h1 / !-- 水平居中 -- Button android:idid/button2 android:layout_widthwrap_content android:layout_heightwrap_content android:textClick Me app:layout_constraintStart_toStartOfparent app:layout_constraintEnd_toEndOfparent/ !-- 垂直居中 -- Button android:idid/button3 android:layout_widthwrap_content android:layout_heightwrap_content android:text点击我 app:layout_constraintTop_toTopOfparent app:layout_constraintBottom_toBottomOfparent/ /androidx.constraintlayout.widget.ConstraintLayout