how to make the buttons fit to all screens?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



how to make the buttons fit to all screens?



I have used buttons as squares shapes(165dpx165dp), but when i change the screen size the button keep the same dimension which make it invisible or too large in some screens.



my layout:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="@drawable/fneclis_l1s1_bg"
tools:context=".AllButtonsFragment">

<ScrollView
android:layout_width="match_parent"
android:layout_height="404dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
tools:ignore="UselessParent">

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Button
android:id="@+id/Phy1"
android:layout_width="165dp"
android:layout_height="165dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:background="@color/bl"
android:text="@string/physique_1"
android:textColor="@color/cardview_light_background"
android:textSize="18sp"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/Infor1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/Math1"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/Math1"
android:layout_width="165dp"
android:layout_height="165dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:background="@color/rd"
android:text="@string/math_matiques_1"
android:textColor="@color/cardview_light_background"
android:textSize="18sp"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/Chemie1"
app:layout_constraintEnd_toStartOf="@+id/Phy1"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/Chemie1"
android:layout_width="165dp"
android:layout_height="165dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:background="@color/or"
android:text="@string/structure_de_la_mati_re"
android:textColor="@color/cardview_light_background"
android:textSize="18sp"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/MR"
app:layout_constraintEnd_toStartOf="@+id/Infor1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Math1" />

<Button
android:id="@+id/Infor1"
android:layout_width="165dp"
android:layout_height="165dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:background="@color/gr"
android:text="@string/informatique_1"
android:textColor="@color/cardview_light_background"
android:textSize="18sp"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/MST1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/Chemie1"
app:layout_constraintTop_toBottomOf="@+id/Phy1" />

<Button
android:id="@+id/MST1"
android:layout_width="165dp"
android:layout_height="165dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:layout_weight="1"
android:background="@color/rd"
android:text="@string/les_m_tiers_en_sciences_et_technologies_1"
android:textColor="@color/cardview_light_background"
android:textSize="18sp"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/Fr"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/MR"
app:layout_constraintTop_toBottomOf="@+id/Infor1" />

<Button
android:id="@+id/MR"
android:layout_width="165dp"
android:layout_height="165dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_weight="1"
android:background="@color/bl"
android:text="@string/m_thodologie_de_la_r_daction"
android:textColor="@color/cardview_light_background"
android:textSize="18sp"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/An"
app:layout_constraintEnd_toStartOf="@+id/MST1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Chemie1" />

<Button
android:id="@+id/An"
android:layout_width="165dp"
android:layout_height="165dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_weight="1"
android:background="#07254e"
android:text="@string/anglais"
android:textColor="@color/cardview_light_background"
android:textSize="18sp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/Fr"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/MR" />

<Button
android:id="@+id/Fr"
android:layout_width="165dp"
android:layout_height="165dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:layout_weight="1"
android:background="@color/jn"
android:text="@string/fran_ais"
android:textColor="@color/cardview_light_background"
android:textSize="18sp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/An"
app:layout_constraintTop_toBottomOf="@+id/MST1" />

</android.support.constraint.ConstraintLayout>
</ScrollView>

</RelativeLayout>



i want to make my button more Interact with screens sizes if that
possible



this is just to avoid the stupid notice of 'it looks like your question is only a code'
I have used buttons as squares shapes(165dpx165dp), but when i change the screen size the button keep the same dimension which make it invisible or too large in some screens.





share your layout file
– Krishna Sharma
Aug 12 at 19:36





the button keep the same dimension!! You set them to keep the same dimension
– mTak
Aug 12 at 19:37






You set the dimension to be 165dp so this is what you get
– mTak
Aug 12 at 20:12





so what mus i do ? please
– Hon Ey Mon Ey
Aug 12 at 20:17





@HonEyMonEy did you try it?
– mTak
Aug 12 at 20:58




2 Answers
2



If you want the buttons to change the dimension side by side and fit all screen sizes and orientation, then you can accomplish it with weights on a Linear layout.





please check my layout and change it to be flexible !!
– Hon Ey Mon Ey
Aug 12 at 20:19



Try setting android:layout_width="0dp" to for each button


android:layout_width="0dp"





i tried but like that i lose the squares shape of the buttons
– Hon Ey Mon Ey
Aug 13 at 9:48






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard