我已经将按钮用作正方形形状(165dpx165dp),但是当我更改屏幕尺寸时,按钮保持相同的尺寸,这使其在某些屏幕上不可见或太大。
我的布局:
<?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>
我想让我的按钮与屏幕尺寸更加互动,如果那样的话 可能
这只是为了避免愚蠢的通知“看起来您的问题只是一个代码” 我已经将按钮用作正方形形状(165dpx165dp),但是当我更改屏幕尺寸时,按钮保持相同的尺寸,这使其在某些屏幕上不可见或太大。
答案 0 :(得分:2)
如果您希望按钮并排更改尺寸并适合所有屏幕尺寸和方向,则可以使用线性布局上的权重来实现。