How could I get an image inside a <Scroolview to stay fixed and all the content "scroll" through the "bottom" of the image?

Asked

Viewed 190 times

2

Hello, I wonder how I could do to keep a picture fixed and the information rolls underneath it, with all this inside a Scrollview, follows layout print and XML pic. de como está atualmente

Code:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"> 
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.hs.gui.testelayout.TelaTres"
    android:orientation="vertical"> 
<TextView
    android:layout_width="100dp"
    android:layout_height="15dp"
    android:text="Tela 3 - | - Final"/>
<ImageView
    android:layout_width="350dp"
    android:layout_height="250dp"
    android:paddingLeft="15dp"
    android:paddingRight="15dp"
    android:paddingBottom="15dp"
    android:foregroundGravity="center"
    android:src="@drawable/guerra_civil_2"
    android:scrollIndicators="start"
    />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/sinopse_CivWar"
    android:textSize="25dp"/>
</LinearLayout>
</ScrollView>

I thought about keeping the image out of Scrollview but that doesn’t seem possible (or I don’t know how) Thank you for your attention :)

2 answers

1

For this, one should use a RelativeLayout

Example:

<?xml version="1.0" encoding="utf-8"?>
< RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Imagem fora do ScrowView, fica fixa -->
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageView"
        android:src="@mipmap/ic_launcher"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scrollView"
        android:background="@android:color/transparent"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" >

        <LinearLayout
            android:orientation="horizontal"
            android:background="@android:color/transparent"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <!-- Coloque aqui os TextView-->

            <TextView
                android:layout_width="301dp"
                android:layout_height="1680dp"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/texto"
                android:id="@+id/textView"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_marginLeft="38dp"
                android:layout_marginStart="38dp"
                android:layout_marginTop="103dp" />


        </LinearLayout>
    </ScrollView>

</RelativeLayout>
  • But would using Relativelayout not "break" the organization? Yes I have difficulty dealing with relative... Grateful :)

  • No! Relax! I had difficulties with him too! But if you train ( start mecher to see how it works ) you get the hang of it quickly!

1


I managed to turn the main layout into LinearLayout, and putting the static elements right at the beginning. Right below I put the ScrollView with the sole element scrolable that was the synopsis:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

  <!--Elementos Estaticos-->
    <TextView
        android:layout_width="100dp"
        android:layout_height="15dp"
        android:text="@string/titulo"/>


    <ImageView
        android:layout_width="350dp"
        android:layout_height="250dp"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:paddingBottom="15dp"
        android:src="@drawable/civilwar"/>

       <!--Elementos Moveis-->
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/sinopse_CivWar"
                android:textSize="25dp"/>

        </LinearLayout>

    </ScrollView>
</LinearLayout>

Follows print:

Print-1 de exemplo da implementação Print-2 de exemplo da implementação

Browser other questions tagged

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