2017-11-28 1 views
1

내가이 버튼 레이아웃중복 버튼

enter image description here

내가
  <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="0.5" 
       android:lay="10dp"> 
       <View android:id="@+id/strut" 
        android:layout_width="0dp" 
        android:layout_height="0dp" 
        android:layout_centerHorizontal="true"/> 

       <Button 
        android:id="@+id/button4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignRight="@id/strut" 
        android:layout_alignParentLeft="true" 
        android:background="@drawable/notificacion_desactivado" /> 
       <Button 
        android:id="@+id/button6" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignLeft="@id/strut" 
        android:layout_alignParentRight="true" 
        android:background="@drawable/alarma_desactivada" /> 
       <Button 
        android:id="@+id/button5" 
        android:layout_width="100dp" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="dp" 

        android:background="@drawable/icono_notificacion_suelto" /> 

      </RelativeLayout> 

했다

를 만들려면 지금은 이런 일이 : enter image description here을하지만 중앙을 만드는 방법을 알고하지 않습니다 버튼을 사용하여 상대 레이아웃을 겹치게하고 여백과 여백을 사용했지만 버튼을 레이아웃 위에 배치 할 수는 없습니다.

+0

과도한 수준의 중첩. 하나의 RelativeLayout으로 충분합니다. –

+0

그냥 중앙 더미보기 (0px 너비와 높이)를 설정하십시오. 하나의 버튼을 왼쪽으로 설정하고 다른 하나는 오른쪽으로 설정하십시오. 그리고 마지막으로 센터에 또 하나. 끝난. –

+1

예, 그게 해결책이었습니다. – El0din

답변

1

ConstraintLayout을 사용하는 방법입니다. 두 번째 버튼을 LinearLayout 안에있는 세 번째 버튼 아래에 표시해야하는 위치에 배치하고 이에 따라 세 번째 버튼을 제한하십시오.

<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"> 

    <LinearLayout 
     android:id="@+id/buttonLayout" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="38dp" 
     android:layout_marginEnd="8dp" 
     android:layout_marginStart="8dp" 
     android:orientation="horizontal" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="parent"> 

     <Button 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"/> 

     <Button 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

    </LinearLayout> 

    <Button 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     app:layout_constraintEnd_toEndOf="@id/buttonLayout" 
     app:layout_constraintStart_toStartOf="@id/buttonLayout" 
     app:layout_constraintBottom_toBottomOf="@id/buttonLayout" 
     app:layout_constraintTop_toTopOf="@id/buttonLayout" 
     android:layout_marginBottom="30dp" 
     android:background="@color/colorAccent"/> 

</android.support.constraint.ConstraintLayout> 

이 출력이 위 또는 아래로 3 버튼을 이동

enter image description here

변경 같은 android:layout_marginBottom 값을 보는 방법이다.

희망이 도움이됩니다.

+1

잘 작동합니다. 감사합니다! – El0din

+0

작동하고 upvote 귀하의 대답 – El0din

+0

@ El0din 나는 당신이 지금까지 물어 질문에 대한이 짓을하지 않은 것을 참조하십시오; 일반적으로 답 옆에있는 체크 표시를 치면 해답을 수락합니다. ** **이 답변은 해결책으로 표시되며 향후 사용자에게 도움이됩니다. –

1
This code works for me :) 
<RelativeLayout android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <View android:id="@+id/strut" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_centerHorizontal="true"/> 

    <Button 
     android:id="@+id/button4" 
     android:layout_width="wrap_content" 
     android:layout_height="60dp" 
     android:layout_alignRight="@id/strut" 
     android:layout_alignParentLeft="true" 
     android:background="@color/text_gray" /> 
    <Button 
     android:id="@+id/button6" 
     android:layout_width="wrap_content" 
     android:layout_height="60dp" 
     android:layout_alignLeft="@id/strut" 
     android:layout_alignParentRight="true" 
     android:background="@color/red" /> 
    <Button 
     android:id="@+id/button5" 
     android:layout_width="60dp" 
     android:layout_height="60dp" 
     android:layout_centerHorizontal="true" 
     android:background="@drawable/app_logo_main" /> 

</RelativeLayout> 
+0

멋진 솔루션이지만, 왼쪽 또는 rigth 버튼을 클릭하면 중앙을 겹쳐 씁니다. 그러나 그것은 나를 위해 일한다, 고마워한다! – El0din

+0

환영합니다. 내 기쁨입니다. 버튼 대신 텍스트 뷰를 사용하면보기를 사용자 정의 할 수 있습니다. :) –

+0

textview 예, 내 앱에 대한 답변입니다. 다음 버전에 대한 답변을드립니다. 정말로 감사합니다. – El0din