How to put Scroll in a layout already made in Android Studio?

Asked

Viewed 1,019 times

0

inserir a descrição da imagem aqui

I have this layout already done, but in smaller cell phones the buttons are inaccessible, I would like to implement Scrolls both vertically and horizontally when necessary

This is the xml of my layout:

<?xml version="1.0" encoding="utf-8"?>

android:layout_height="match_parent"
android:visibility="visible"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".controlador.MainActivity"
tools:showIn="@layout/activity_main">


<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"
    android:adjustViewBounds="true"
    android:src="@drawable/banner"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<EditText
    android:id="@+id/edtnsd"
    android:layout_width="80dp"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="number|numberDecimal"
    app:layout_constraintBottom_toBottomOf="@+id/textView3"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.465"
    app:layout_constraintStart_toStartOf="parent" />

<EditText
    android:id="@+id/edtmdx"
    android:layout_width="80dp"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="number|numberDecimal"
    app:layout_constraintBottom_toBottomOf="@+id/textView5"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.465"
    app:layout_constraintStart_toStartOf="parent" />

<EditText
    android:id="@+id/edtmdy"
    android:layout_width="80dp"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="number|numberDecimal"
    app:layout_constraintBottom_toBottomOf="@+id/textView8"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.465"
    app:layout_constraintStart_toStartOf="parent" />

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="120dp"
    android:text="Solicitações:"
    android:textSize="30sp"
    android:textStyle="bold"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="90dp"
    android:layout_marginLeft="90dp"
    android:layout_marginTop="28dp"
    android:layout_marginEnd="14dp"
    android:layout_marginRight="14dp"
    android:text="Nsd:"
    android:textSize="24sp"
    android:textStyle="bold"
    app:layout_constraintEnd_toStartOf="@+id/edtnsd"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView" />

<TextView
    android:id="@+id/textView6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="86dp"
    android:layout_marginLeft="86dp"
    android:layout_marginTop="52dp"
    android:layout_marginEnd="14dp"
    android:layout_marginRight="14dp"
    android:text="Mdx:"
    android:textSize="24sp"
    android:textStyle="bold"
    app:layout_constraintEnd_toStartOf="@+id/edtmdx"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView2" />

<TextView
    android:id="@+id/textView7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="86dp"
    android:layout_marginLeft="86dp"
    android:layout_marginTop="56dp"
    android:layout_marginEnd="14dp"
    android:layout_marginRight="14dp"
    android:text="Mdy:"
    android:textSize="24sp"
    android:textStyle="bold"
    app:layout_constraintEnd_toStartOf="@+id/edtmdy"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView6" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="28dp"
    android:text="kN"
    android:textSize="24sp"
    android:textStyle="bold"
    app:layout_constraintStart_toEndOf="@+id/edtnsd"
    app:layout_constraintTop_toBottomOf="@+id/textView" />

<TextView
    android:id="@+id/textView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="52dp"
    android:text="kN.m"
    android:textSize="24sp"
    android:textStyle="bold"
    app:layout_constraintStart_toEndOf="@+id/edtmdx"
    app:layout_constraintTop_toBottomOf="@+id/textView3" />

<TextView
    android:id="@+id/textView8"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="55dp"
    android:text="kN.m"
    android:textSize="24sp"
    android:textStyle="bold"
    app:layout_constraintStart_toEndOf="@+id/edtmdy"
    app:layout_constraintTop_toBottomOf="@+id/textView5" />

<TextView
    android:id="@+id/statusbarra"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:text="Analisando..."
    android:textSize="14sp"
    android:textStyle="bold"
    android:visibility="invisible"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/load" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:onClick="analisar"
    android:text="ANALISAR"
    android:visibility="visible"

    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/edtmdy" />

<ProgressBar
    android:id="@+id/load"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="250dp"
    android:layout_height="33dp"
    android:layout_marginTop="16dp"
    android:contentDescription="Analisando..."
    android:progress="0"
    android:visibility="invisible"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.496"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/button" />

<Button
    android:id="@+id/continuar01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="33dp"
    android:layout_marginEnd="35dp"
    android:layout_marginRight="35dp"
    android:onClick="chamarzx"
    android:text="Proseguir >>"
    android:visibility="invisible"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/load" />

<ScrollView
    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="match_parent">

    </LinearLayout>

</ScrollView>

1 answer

1

Face is pretty simple, actually. You can simply nest the Verticalscrollview and Horizontalscrollview classes to get the required result. See a possible solution.

<!--layout.xml-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

        </LinearLayout>
    </HorizontalScrollView>
</ScrollView>

  • I’m starting now on android, how would I put this in xml? I tried to copy all the xml that is in the question into where to be commented, but all the elements disappear and the application closes when running.

  • Okay, see if it works now. I added the Android namespace. And just to remember the scrollview only accepts a child

Browser other questions tagged

You are not signed in. Login or sign up in order to post.