Android开发学习

121 阅读2分钟

kotlin学习

地址 www.runoob.com/kotlin/kotl…

kotlin我感觉比较有意思的地方时 类的创建,和对象表达式。使用起来相对于OC Swift Dart语言比较新颖和方便。

布局学习

juejin.cn/post/694918…

Android的布局用起来和Flutter有着微妙的相似之处。

我下边只记录一下以后工作中可能需要的属性/功能。

RelativeLayout(相对布局)中根据兄弟组件定位。

这几个属性非常重要,UI搭建时用的频率也是非常的高。

属性描述
layout_toLeftOf控制该组件在兄弟组件的左侧。
layout_toRightOf控制该组件在兄弟组件的右侧。
layout_above控制该组件在兄弟组件的上方。
layout_below控制该组件在兄弟组件的下方。
layout_alignTop控制该组件在兄弟组件的上边界。
layout_alignBottom控制该组件在兄弟组件的下边界。
layout_alignLeft控制该组件在兄弟组件的左边界。
layout_alignRight控制该组件在兄弟组件的右边界。

ConstraintLayout(约束布局)

这个也很重要,而且属性很多了。

属性描述
layout_constraintTop_toTopOf我的顶部和谁的顶部对齐
app:layout_constraintBottom_toBottomOf我的底部和谁的底部对齐
app:layout_constraintLeft_toLeftOf我的左边和谁的左边对齐
app:layout_constraintRight_toRightOf我的右边和谁的右边对齐
app:layout_constraintStart_toStartOf我的开始位置和谁的开始位置对齐
app:layout_constraintEnd_toEndOf我的结束位置和谁的结束位置对齐
app:layout_constraintTop_toBottomOf我的顶部位置在谁的底部位置
app:layout_constraintStart_toEndOf我的开始位置在谁的结束为止
app:layout_constraintBaseline_toBaselineOf我的Y轴中心点和谁的Y轴中心点对其
app:layout_constraintCircle参考控件ID
app:layout_constraintCircleAngle角度: 0-360
app:layout_constraintCircleRadius两个组件中心点距离
app:layout_constraintVertical_bias0-1
app:layout_constraintHorizontal_bias0-1
外边距设置
android:layout_margin
android:layout_marginStart
android:layout_marginLeft
android:layout_marginTop
android:layout_marginEnd
android:layout_marginRight
android:layout_marginBottom
内边距设置
android:padding
android:paddingStart
android:paddingLeft
android:paddingTop
android:paddingEnd
android:paddingRight
android:paddingBottom

例如

app:layout_constraintTop_toTopOf=""

属性的 = 后面可以填写 parent(父类),也可以填写 某个组件的id @+id/textView9527

举个例子:有两个view,但是A胖B瘦,达到图中效果需要:

image.png

//B首先需要到在A下方
app:layout_constraintTop_toBottomOf="@+id/textView9527"
//然后左对齐(当然你可以选择右对齐)
app:layout_constraintStart_toStartOf="@+id/textView9527"

如果要达到下图中效果

image.png

//先底部位置统一
app:layout_constraintBottom_toBottomOf="@+id/textView9527"
//再站到一起
app:layout_constraintStart_toEndOf="@+id/textView9527"

注 :layout_constraintVertical_bias layout_constraintHorizontal_bias 这两个属性使用时需要把下面四个属性都设置上才能生效

app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"

东西太多了,暂未学完。。。