1

У меня есть activity мне надо, чтобы оно настраивалось под диагональ экрана пользователя. Я писал активность под диагональ экрана своего телефона. А потом попробовал запустить приложение на другом телефоне и некоторые фрагменты там не поместились.

Код разметки:

<TextView
    android:id="@+id/textView"
    android:layout_width="142dp"
    android:layout_height="29dp"
    android:layout_marginBottom="68dp"
    android:layout_marginLeft="112dp"
    android:layout_marginRight="120dp"
    android:layout_marginStart="112dp"
    android:layout_marginTop="8dp"
    android:visibility="visible"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/btt8" />

<ImageButton
    android:id="@+id/btt1"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginEnd="24dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/buttons"
    app:layout_constraintEnd_toStartOf="@+id/btt2"
    app:layout_constraintHorizontal_bias="0.4"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<ImageButton
    android:id="@+id/btt2"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginEnd="24dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/buttons"
    app:layout_constraintEnd_toStartOf="@+id/btt3"
    app:layout_constraintTop_toTopOf="parent" />

<ImageButton
    android:id="@+id/btt4"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginEnd="24dp"
    android:layout_marginStart="8dp"
    android:background="@drawable/buttons"
    android:layout_marginTop="8dp"
    app:layout_constraintEnd_toStartOf="@+id/btt5"
    app:layout_constraintHorizontal_bias="0.285"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/btt1" />

<ImageButton
    android:id="@+id/btt5"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginEnd="24dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/buttons"
    app:layout_constraintEnd_toStartOf="@+id/btt6"
    app:layout_constraintTop_toBottomOf="@+id/btt2" />

<ImageButton
    android:id="@+id/btt6"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginEnd="16dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/buttons"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/btt3" />

<ImageButton
    android:id="@+id/btt3"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginEnd="16dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/buttons"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<ImageButton
    android:id="@+id/bt7"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginEnd="24dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/buttons"
    app:layout_constraintEnd_toStartOf="@+id/btt8"
    app:layout_constraintHorizontal_bias="0.285"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/btt4" />

<ImageButton
    android:id="@+id/btt8"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginEnd="24dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/buttons"
    app:layout_constraintEnd_toStartOf="@+id/btt9"
    app:layout_constraintTop_toBottomOf="@+id/btt5" />

<ImageButton
    android:id="@+id/btt9"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginEnd="16dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/buttons"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/btt6" />

<Button
    android:id="@+id/button10"
    android:layout_width="116dp"
    android:layout_height="38dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="16dp"
    android:layout_marginTop="8dp"
    android:text="Back"
    android:background="@drawable/field"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/btt9"
    app:layout_constraintVertical_bias="0.957" />

<Button
    android:id="@+id/button11"
    android:layout_width="113dp"
    android:layout_height="38dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="16dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="16dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="Restart"
    android:background="@drawable/field"
    android:visibility="invisible"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.497"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/btt8"
    app:layout_constraintVertical_bias="0.957" />

<Button
    android:id="@+id/button14"
    android:layout_width="113dp"
    android:layout_height="38dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="16dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="16dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="Main Menu"
    android:background="@drawable/field"
    android:visibility="invisible"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/bt7"
    app:layout_constraintVertical_bias="0.956" />

4
  • Покажи XML разметку.. Какие параметры задал своим "фрагментам"..
    – Игорь
    27 июл 2018 в 7:46
  • Я в ответи код кинул 27 июл 2018 в 8:20
  • 1
    Ответы предназначены для ответов. Нужно добавлять код в текст вопроса. 27 июл 2018 в 8:56
  • нужно что то узнать о адаптивной ("резиновой") верстке, а не хардкорить размеры виджетов.
    – pavlofff
    27 июл 2018 в 9:48

1 ответ 1

0

Элементы экрана надо запаковывать в контейнеры. В данный момент LinerLayout с вертикальной ориентацией, в котором будет три LinerLayout с горизонтальной ориентацией, по три ImageButton. Четвертым элементом там будет текст.

 <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal"
       android:gravity="center_horizontal">

       <ImageButton
           android:layout_width="100dp"
           android:layout_height="100dp"
           android:layout_margin="8dp"/>
       <ImageButton
           android:layout_width="100dp"
           android:layout_height="100dp"
           android:layout_margin="8dp"/>
       <ImageButton
           android:layout_width="100dp"
           android:layout_height="100dp"
           android:layout_margin="8dp"/>
   </LinearLayout>

   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal"
       android:gravity="center_horizontal">

       <ImageButton
           android:layout_width="100dp"
           android:layout_height="100dp"
           android:layout_margin="8dp"/>
       <ImageButton
           android:layout_width="100dp"
           android:layout_height="100dp"
           android:layout_margin="8dp"/>
       <ImageButton
           android:layout_width="100dp"
           android:layout_height="100dp"
           android:layout_margin="8dp"/>
   </LinearLayout>

   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal"
       android:gravity="center_horizontal">

       <ImageButton
           android:layout_width="100dp"
           android:layout_height="100dp"
           android:layout_margin="8dp"/>
       <ImageButton
           android:layout_width="100dp"
           android:layout_height="100dp"
           android:layout_margin="8dp"/>
       <ImageButton
           android:layout_width="100dp"
           android:layout_height="100dp"
           android:layout_margin="8dp"/>
   </LinearLayout>

       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="TEXT"
           android:layout_gravity="center"/>

Вне этого контейнера создаем еще один LinerLayout и привязываем его к низу. В нем будет три кнопки.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal">

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

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

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

Не забываем параметры gravity и weigth, которые указывают поведение элемента в контейнере. Так же основной контейнер разметки тут RelativeLayout, можно и с вашим, но мне так проще. Вот здесь хорошо объясняется про поведение компонентов экрана. http://developer.alexanderklimov.ru/android/views/

3
  • Игорь, с вами можно как-то связаться? 27 июл 2018 в 11:34
  • [email protected]
    – Игорь
    27 июл 2018 в 12:24
  • Я вам написал на почту 27 июл 2018 в 12:38

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.