2017-04-27 12 views
0

대형 화면에서는 가로로, 작은 화면에서는 세로로 단추를 배치하고 싶습니다 (화면 해상도에 맞지 않는 경우). 화면 해상도에 의존하는 xml에 두 개의 레이아웃을 만들지 않고 ConstraintLayout을 사용하여이 작업을 수행 할 수 있습니까? 그 동작에 대해 "제약 조건"을 어떻게 설정할 수 있습니까?ConstraintLayout에서 하나의 단추를 다른 단추보다 아래쪽에 배치하면 화면에 맞지 않습니다.

NOW IT WORKS LIKE THIS

그것은 당신이 할 수 없습니다 XML

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <Button 
     android:id="@+id/button5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="First button" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@+id/button3" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Second button" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toRightOf="@+id/button5" 
     app:layout_constraintRight_toRightOf="parent" /> 

</android.support.constraint.ConstraintLayout> 
+0

버튼의 정적 너비를 설정 했습니까? –

+0

버튼의 너비와 높이는 "wrap_content"에 있습니다. 나는 또한 질문에 XML을 추가했습니다. – lukjar

답변

0

내 레이아웃입니다 그냥 ConstraintLayout 그. 체인에 Views에 대해 linebreak의 종류를 생성하는 방법을 제공하지 않습니다.

쉽게 할 수있는 여러 라이브러리가 있습니다. 그러나 다른 레이아웃을 소개해야합니다. 예 : android-flowlayout.