저는 최근에 안드로이드 스튜디오에서 ConstraintLayout으로 재생하기 시작했습니다. (나중에 내 앱에서 사용할 수 있습니다.) 한 행에 5 개의 버튼이 있고 5 개의 행이 10 개있는 레이아웃을 만들고 싶습니다. 버튼. 버튼 전체 간격을 채우는 동안 버튼이 모두 같은 너비로 크기 조정되기를 바랄 뿐이다.안드로이드 ConstraintLayout 센터 여러개의 버튼으로 수평 정렬하기
내 현재 XML :
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="lotterynumbergenerator.johnferrazlopez.com.southafricanlotteryguide.other.SaveNumbers">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="01"
android:textStyle="bold"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/button2"
tools:layout_editor_absoluteY="16dp" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="02"
android:textStyle="bold"
app:layout_constraintLeft_toRightOf="@+id/button"
app:layout_constraintRight_toLeftOf="@+id/button3"
tools:layout_editor_absoluteY="16dp" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="03"
android:textStyle="bold"
app:layout_constraintLeft_toRightOf="@+id/button2"
app:layout_constraintRight_toLeftOf="@+id/button4"
tools:layout_editor_absoluteY="16dp" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="04"
android:textStyle="bold"
app:layout_constraintLeft_toRightOf="@+id/button3"
app:layout_constraintRight_toLeftOf="@+id/button5"
tools:layout_editor_absoluteY="16dp" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="05"
android:textStyle="bold"
app:layout_constraintLeft_toRightOf="@+id/button4"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="16dp" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="06"
tools:layout_editor_absoluteY="64dp"
app:layout_constraintRight_toLeftOf="@+id/button7"
app:layout_constraintLeft_toLeftOf="parent" />
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="07"
tools:layout_editor_absoluteY="64dp"
app:layout_constraintRight_toLeftOf="@+id/button8"
app:layout_constraintLeft_toRightOf="@+id/button6" />
<Button
android:id="@+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="08"
tools:layout_editor_absoluteY="64dp"
app:layout_constraintRight_toLeftOf="@+id/button9"
app:layout_constraintLeft_toRightOf="@+id/button7" />
<Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="09"
tools:layout_editor_absoluteY="64dp"
app:layout_constraintRight_toLeftOf="@+id/button10"
app:layout_constraintLeft_toRightOf="@+id/button8" />
<Button
android:id="@+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
tools:layout_editor_absoluteY="64dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@+id/button9" />
</android.support.constraint.ConstraintLayout>
나는 XML에서 볼 또 다른 점은 태그에서이 메시지가 "이보기는 세로로 제한되어 있지 않은 것입니다 : 런타임에 왼쪽으로 이동합니다 수직 제약 조건을 추가하지 않는 한 "
미리 감사드립니다.
편집 : 여기
내가 모든 버튼이 고르게 퍼져 원이다. 그래서 디스플레이의 크기에 관계없이 버튼은 모두 축소되거나 커집니다. 기본적으로 그들은 모두 10dp의 동일한 마진을 가져야합니다. 나는 내가 원하는 것을 보여주기 위해 나의 대답을 편집했다. 감사합니다 –
@Think_Twice 업데이트 된 답변보기. – Cheticamp