0
<?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"
    tools:context=".SecondActivity"
    android:orientation="vertical">


    <TextView
        android:id="@+id/question"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/question_from_secodActiv"
        android:textSize="30sp"
        android:paddingTop="8dp"
        android:paddingLeft="8dp"
        android:textAllCaps="false"
        tools:ignore="MissingConstraints" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/question"
        android:layout_alignParentStart="true"
        android:layout_marginTop="8dp"
        android:paddingLeft="8dp"
        android:text="@string/chosen_recomendation"
        android:textSize="15sp" />
    <Button
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="205dp"
        android:text="111111"
        android:textSize="12sp"
        android:textColor="@android:color/white"
        android:background="#c266ff"/>

    <Button
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="270dp"
        android:text="2222222"
        android:textSize="12sp"
        android:textColor="@android:color/white"
        android:background="#ad33ff"/>

    <Button
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:layout_marginTop="335dp"
        android:text="333333"
        android:textSize="12sp"
        android:textColor="@android:color/white"
        android:background="#9900ff"/>

    <Button
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="400dp"
        android:text="4444444"
        android:textSize="12sp"
        android:textColor="@android:color/white"
        android:background="#7a00cc"/>

    <Button
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="465dp"
        android:text="555555"
        android:textSize="12sp"
        android:textColor="@android:color/white"
        android:background="#5c0099"/>

</RelativeLayout>

Необходима подсказка или помощь с одним активити. В одном активити 2 Text View и 5 Button суть в чем, при смене ориентации, не помещаются все элементы, пытался сделать через Recycler ничего не получилось. Как сделать, чтоб независимо от масштабов смартфона все элементы могли помещаться или хотя бы прокручиваться.

1 ответ 1

1

Если вы сидите внутри RelativeLayout, то попытки выравнивания с помощью layout_marginTop и XXXdp до добра не доведут.

Если я правильно понимаю ваш лейаут есть 2 TextView, под которыми вы пытаетесь поместить несколько Button. Способов решения масса, ну например:

Внутри RelativeLayout помещаем оба LinearLayout с флагом orientation=vertical, первый прижимаем к верхней части RelativeLayout атрибутом layout_alignParentTop="true", второй помещаем под ним с атрибутом layout_below="@+id/firstLayout"

В первый пихаем по очереди TextView с атрибутами android:layout_width="match_parent" и android:layout_height="wrap_content", во второй пихаем Button с аналогичными атрибутами

Ваш ответ

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

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