View have a rhombus background. It is necessary to arrange the "buttons" as in the picture.

I made this markup, but at the same time, if the size of the space is not enough, then these buttons start flattening. How can I get rid of static sizes in my case? Or can you tell me how you can make this arrangement differently?

<android.support.constraint.ConstraintLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="10dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintHorizontal_weight="1" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/lastInfoTime" app:layout_constraintVertical_weight="1"> <LinearLayout android:id="@+id/navigation" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginEnd="8dp" android:background="@drawable/button_nav_background" android:gravity="center" android:orientation="vertical" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintDimensionRatio="1" app:layout_constraintEnd_toStartOf="@+id/auto" app:layout_constraintHorizontal_weight="1" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_weight="1"> <android.support.v7.widget.AppCompatTextView android:id="@+id/navigationText" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawablePadding="7dp" android:drawableTop="@drawable/ic_gas_station" android:fontFamily="@font/pfdindisplaypro_light" android:gravity="center" android:text="Навигация" android:textColor="@color/main_text_color" android:textSize="13sp" /> </LinearLayout> <LinearLayout android:id="@+id/auto" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginStart="8dp" android:background="@drawable/button_nav_background" android:gravity="center" android:orientation="vertical" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintDimensionRatio="1" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_weight="1" app:layout_constraintStart_toEndOf="@+id/navigation" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_weight="1"> <android.support.v7.widget.AppCompatTextView android:id="@+id/autoText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawablePadding="7dp" android:drawableTop="@drawable/truck" android:fontFamily="@font/pfdindisplaypro_light" android:gravity="center" android:text="Авто" android:textColor="@color/main_text_color" android:textSize="13sp" /> </LinearLayout> <LinearLayout android:id="@+id/message" android:layout_width="140dp" android:layout_height="140dp" android:layout_alignBottom="@id/navigation" android:layout_marginBottom="8dp" android:layout_toEndOf="@id/navigation" android:background="@drawable/button_nav_background" android:gravity="center" android:orientation="vertical"> <android.support.v7.widget.AppCompatTextView android:id="@+id/messageText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawablePadding="7dp" android:drawableTop="@drawable/ic_action_message" android:fontFamily="@font/pfdindisplaypro_light" android:gravity="center" android:text="Сообщения" android:textColor="@color/main_text_color" android:textSize="13sp" /> </LinearLayout> </android.support.constraint.ConstraintLayout> 

enter image description here

    1 answer 1

    Use ConstraintLayout. Place all the buttons inside it and snap them to its borders. When the parent ConstraintLayout is compressed, all the buttons inside will be automatically mastabed. Separately, I would have worked with the minimum and maximum size of the buttons. If they become too small, it is not convenient. If too big - ugly.

    Addition:

    I will try to explain with the example of 1 pair. Chain the top and bottom, the size of the buttons, set the match parent for the height of the buttons, for the width wrap_content. Set the buttons to the ratio of 1 to 1 (for a constinent, this property is definitely there, not sure about the usual relativized layout). Center both buttons horizontally. Set the padding between the buttons and from the lower-upper border. Then this should be done for the left and right buttons.

    Implementation Usually, it was not in my rules to give a solution, but this time the problem seemed unusual to me (I was not sure that I had considered everything), so I tried and it turned out:

     <android.support.constraint.ConstraintLayout android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintDimensionRatio="1:1" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintHorizontal_weight="1" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_weight="1"> <LinearLayout android:id="@+id/right" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginEnd="32dp" android:layout_marginStart="32dp" android:background="#0026ff" android:gravity="center" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintDimensionRatio="1" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintHorizontal_weight="1" app:layout_constraintStart_toEndOf="@+id/left" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_weight="1"> <android.support.v7.widget.AppCompatTextView android:id="@+id/navigationText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawablePadding="7dp" android:gravity="center" android:text="Right" android:textColor="#000" android:textSize="13sp" /> </LinearLayout> <LinearLayout android:id="@+id/left" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginEnd="32dp" android:layout_marginStart="32dp" android:background="#ffb700" android:gravity="center" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintDimensionRatio="1" app:layout_constraintEnd_toStartOf="@+id/right" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintHorizontal_weight="1" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_weight="1"> <android.support.v7.widget.AppCompatTextView android:id="@+id/autoText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawablePadding="7dp" android:gravity="center" android:text="Left" android:textColor="#000" android:textSize="13sp" /> </LinearLayout> <LinearLayout android:id="@+id/top" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginBottom="32dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="32dp" android:background="#ff0000" android:gravity="center" app:layout_constraintBottom_toTopOf="@+id/bottom" app:layout_constraintDimensionRatio="1" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintHorizontal_weight="1" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_weight="1"> <android.support.v7.widget.AppCompatTextView android:id="@+id/navigationText" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawablePadding="7dp" android:gravity="center" android:text="Top" android:textColor="#000" android:textSize="13sp" /> </LinearLayout> <LinearLayout android:id="@+id/bottom" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginBottom="32dp" android:layout_marginTop="32dp" android:background="#4cff00" android:gravity="center" android:orientation="vertical" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintDimensionRatio="1" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_weight="1" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/top" app:layout_constraintVertical_weight="1"> <android.support.v7.widget.AppCompatTextView android:id="@+id/autoText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawablePadding="7dp" android:gravity="center" android:text="Bottom" android:textColor="#000" android:textSize="13sp" /> </LinearLayout> </android.support.constraint.ConstraintLayout> 

    And it looks like this (I used simple squares, but with diamonds, the overlays will disappear): enter image description here

    • I don’t really understand how I can do this in ConstraintLayout, I just started working with this lajaut. Could you tell me how you can make the buttons so arranged as in the picture above? - DuosDuo
    • one
      I added, I hope that I took everything into account - George Chebotaryov
    • one
      added a possible solution. try to apply it - George Chebotaryov
    • one
      works. Thank. I will delve into this markup) - DuosDuo
    • one
      then be sure to try to do it at leisure with 3 - Georgy Chebotarev