Android涓瑿onstraintLayout甯冨眬鎬庝箞浣跨敤
ConstraintLayout鏄竴绉嶇伒娲诲己澶х殑甯冨眬鏂瑰紡锛屽彲浠ラ€氳繃璁剧疆鍚勭绾︽潫鏉′欢鏉ュ畾涔夋帶浠朵箣闂寸殑浣嶇疆鍏崇郴銆傚湪Android寮€鍙戜腑浣跨敤ConstraintLayout甯冨眬鍙互瀹炵幇澶嶆潅鐨勫竷灞€鏁堟灉锛屽悓鏃跺彲浠ュ噺灏戝竷灞€宓屽锛屾彁楂樻€ц兘銆?/p>
浠ヤ笅鏄娇鐢–onstraintLayout甯冨眬鐨勫熀鏈楠わ細
- 鍦╔ML甯冨眬鏂囦欢涓畾涔塁onstraintLayout浣滀负鏍瑰竷灞€锛屼緥濡傦細
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- 娣诲姞鍏朵粬鎺т欢 -->
</androidx.constraintlayout.widget.ConstraintLayout>
- 鍦–onstraintLayout涓坊鍔犲叾浠栨帶浠讹紝渚嬪TextView銆丅utton绛夛紝骞惰缃畠浠箣闂寸殑绾︽潫鏉′欢锛屼緥濡傦細
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
鍦ㄤ笂闈㈢殑渚嬪瓙涓紝TextView鐨勫乏杈逛笌鐖跺竷灞€鐨勫乏杈瑰榻愶紙app:layout_constraintStart_toStartOf=鈥減arent鈥濓級锛屽彸杈逛笌鐖跺竷灞€鐨勫彸杈瑰榻愶紙app:layout_constraintEnd_toEndOf=鈥減arent鈥濓級锛岄《閮ㄤ笌鐖跺竷灞€鐨勯《閮ㄥ榻愶紙app:layout_constraintTop_toTopOf=鈥減arent鈥濓級锛屽簳閮ㄤ笌鐖跺竷灞€鐨勫簳閮ㄥ榻愶紙app:layout_constraintBottom_toBottomOf=鈥減arent鈥濓級銆?/p>
- 鏍规嵁瀹為檯闇€姹傝缃叾浠栨帶浠朵箣闂寸殑绾︽潫鏉′欢锛屼緥濡備袱涓帶浠朵箣闂寸殑姘村钩鎴栧瀭鐩存柟鍚戠殑璺濈銆佸榻愮瓑銆?/li>
閫氳繃浠ヤ笂姝ラ锛屽彲浠ヤ娇鐢–onstraintLayout甯冨眬瀹炵幇鐏垫椿澶氭牱鐨勭晫闈㈠竷灞€鏁堟灉銆侰onstraintLayout杩樻彁渚涗簡鍥惧舰鍖栫紪杈戝櫒锛屽彲浠ユ柟渚垮湴鎷栨嫿鎺т欢骞惰缃害鏉熸潯浠讹紝蹇€熷疄鐜板鏉傜殑甯冨眬銆?/p>
相关问答