android 新的布局,Android新布局方式ConstraintLayout快速入门教程
前言
在android開(kāi)發(fā)中,我們通常是手寫布局,很少會(huì)用拖動(dòng)來(lái)寫布局,雖然constraintlayout在i/o上以拖動(dòng)來(lái)展現(xiàn)了各種功能,我估計(jì)在以后開(kāi)發(fā)中,程序員還是習(xí)慣手?jǐn)]代碼。
我自己試著拖著用了一下,用得不是很明白 ,而且用起來(lái)效果不是很好。
那么
直接上手?jǐn)]了一下~~~
其實(shí)很簡(jiǎn)單
button1:app:layout_constraintbottom_totopof="@id/iv_head"
我們把這個(gè)屬性拆開(kāi)來(lái)看,constraintbottom指的本身的底部,即button1的頂部,totopof是指imageview的頂部,那么這句話的意思就是
aligns the bottom of the desired view to the top of another.(官方原文)
翻譯一下就是button1的底部要和imageview的頂部對(duì)齊
button1 app:layout_constraintright_toleftof="@id/iv_head"
根據(jù)上面的規(guī)則我們就知道button1的右邊要和imageview的左邊對(duì)齊。
其實(shí)很簡(jiǎn)單就是說(shuō)兩個(gè)view的某個(gè)方位要對(duì)齊
沒(méi)了,就這么簡(jiǎn)單,其它屬性可以舉一反三,它比relativelayout控制起來(lái)更加得以就手。
layout_constrainttop_totopof?—?align the top of the desired view to the top of another.
layout_constrainttop_tobottomof?—?align the top of the desired view to the bottom of another.
layout_constraintbottom_totopof?—?align the bottom of the desired view to the top of another.
layout_constraintbottom_tobottomof?—?align the bottom of the desired view to the bottom of another.
layout_constraintleft_totopof?—?align the left of the desired view to the top of another.
layout_constraintleft_tobottomof?—?align the left of the desired view to the bottom of another.
layout_constraintleft_toleftof?—?align the left of the desired view to the left of another.
layout_constraintleft_torightof?—?align the left of the desired view to the right of another.
layout_constraintright_totopof?—?align the right of the desired view to the top of another.
layout_constraintright_tobottomof?—?align the right of the desired view to the bottom of another.
layout_constraintright_toleftof?—?align the right of the desired view to the left of another.
layout_constraintright_torightof?—?align the right of the desired view to the right of another.
if desired, attributes supporting start and end are also available in place of left and right alignment.
到此,你已經(jīng)掌握了一大半的constraintlayout知識(shí)點(diǎn)
還有其它的一些屬性
app:layout_constraintstart_toendof
意思就是button的開(kāi)始部分(從左往右看,開(kāi)始部分就是button的左邊)與imageview的右邊是對(duì)齊的。
app:layout_constraintstart_tostartof
這個(gè)就是說(shuō)button的左邊與imageview的左邊是對(duì)齊的
不知道為什么上面已經(jīng)出的屬性能夠滿足布局需要了,為什么還要再出start和end的。
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)萬(wàn)仟網(wǎng)的支持。
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的android 新的布局,Android新布局方式ConstraintLayout快速入门教程的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 布局打印快捷键bpt(批量打印布局快捷键
- 下一篇: android查看wifi是否双频,An