安卓开发ui设计的问题以及解决方法
1. 页面部分占用1/n的情况
解决方案;
使用线性布局,其属性android:orientation=vertical,android:weightsum=3
线性布局里面有两个相对布局,分别设置两个相对布局的layout_weight
关于其中的权重比为2:1,参阅android布局中的layout_weight和weightsum属性的详解及使用
<linearlayout
android:orientation=vertical
...
android:weightsum=3>
<!-- 上部 -->
<relativelayout
android:layout_weight=2
android:id=@+id/top
android:layout_width=match_parent
android:layout_height=match_parent
android:background=@color/colorprimarydark>
...
</relativelayout>
<!-- 中部和底部 -->
<relativelayout
android:id=@+id/middle
android:layout_weight=1
android:layout_width=match_parent
android:layout_height=match_parent>
...
</relativelayout>
</linearlayout>
2. 分割线的实现
分割线的实现,方法比较粗暴,直接使用imageview组件实现
给其src设置为一个颜色,然后修改其weight(对应分割线的宽度)以及height(对应分割线的高度)属性以及位置设置
<imageview
android:id=@+id/horline2
android:layout_width=match_parent
android:layout_height=15dp
android:layout_below=@+id/info
android:layout_margintop=15dp
android:src=#1e000000/>
3. 多个组件高度一致,顶对齐,并且水平均匀分布
例子:需要实现下图的情况,需要三个button高度一致,顶对齐并且水平均匀分布
在这里插入图片描述
首先需要了解一下约束布局以其使用
约束布局(constraintlayout),布局内组件按各种约束排列。每个组件受到三类约束,即其他组件,父容器(parent),基准线(guideline)。 约束布局代码可归纳为以下形式:app:layout_constraint[组件本身的位置]_to[目标位置]of=[目标id]。因此若想要组件水平居中,只需设置组件的左右边界与父容器的左右边界分别对齐。同理,组件的垂直居中也可以这么设置。
再思考本问题,是否也能使用约束布局来完成呢?使用约束布局,将三个按钮放在一个约束布局里面,每个按钮视图的左侧或者右侧与需要的对齐按钮的相应侧对齐即可,则组件之间就可以处于均匀分布了。
<android.support.constraint.constraintlayout
android:layout_width=match_parent
android:layout_height=wrap_content>
<button
app:layout_constraintright_toleftof=@+id/loadbtn
app:layout_constraintleft_toleftof=parent
android:id=@+id/savebtn
android:text=save
android:layout_width=wrap_content
android:layout_height=wrap_content />
<button
android:id=@+id/loadbtn
android:text=load
app:layout_constraintleft_torightof=@+id/savebtn
app:layout_constraintright_toleftof=@+id/clearbtn
android:layout_width=wrap_content
android:layout_height=wrap_content />
<button
android:layout_width=wrap_content
android:layout_height=wrap_content
app:layout_constraintleft_torightof=@+id/loadbtn
app:layout_constraintright_torightof=parent
android:id=@+id/clearbtn
android:text=clear/>
</android.support.constraint.constraintlayout>
安卓
不确定的网站交互周期网站改版会对网站推广优化产生影响吗SEO中的建设内容很重要网站代码优化的策略企业网站快速提升关键词优化效果的技巧都有哪些?免备案香港BGP多线服务器优势是什么网站建设之四大要点你造吗?企业容器化如何选型?全方位对比 Heroku 与 Docker