2017-11-28 3 views
1

私はオーバーラップボタン

  <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

レベルが多すぎます。 1つのRelativeLayoutで十分です。 –

+0

中央ダミーのビューを設定するだけで(幅0px、高さ0px)ボタンを左に設定し、もう一方を右に設定します。そして最後にもう1つは中央にあります。完了しました。 –

+1

はい、それは解決策でした、たくさんのthx! – El0din

答えて

1

これは、ConstraintLayoutを使用してこれを行う方法です。 2番目のボタンをLinearLayoutの3番目のボタンの下に表示する必要がある位置に配置し、それに応じて3番目のボタンを押し込みます。

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

これは、出力が変更

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

素晴らしい解決策ですが、左またはリグのボタンをクリックすると中央がオーバーラップします。しかし、それは私のために働く、ありがとう! – El0din

+0

あなたの歓迎、私はあなたのビューをカスタマイズすることができるようにボタンの代わりにtextviewを使用することをお勧めします:) –

+0

textviewはい、私のアプリへの答えです、私は次のバージョンでは、本当にありがとう! – El0din