Hello i make my first app in Android Studio. I was read a lot of topics about my problem and still doesn't find solution. Every topics and video are about ScrollView as a "view" of application. I want a scroll only some part of screen (selected part)
What i should do to achieve effect that i want?
My XML Code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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/bg"
android:theme="@style/Theme.PlayRPGMobile"
tools:context=".DashActivity">
<ImageView
android:id="@ id/logo"
android:layout_width="0dp"
android:layout_height="@dimen/_32sdp"
android:layout_marginTop="@dimen/_32sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@ id/guideline6"
app:srcCompat="@drawable/logo" />
<androidx.constraintlayout.widget.Guideline
android:id="@ id/guideline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="20dp"
app:layout_constraintGuide_percent="0.0" />
<androidx.constraintlayout.widget.Guideline
android:id="@ id/guideline7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="20dp"
app:layout_constraintGuide_percent="0.3" />
<TextView
android:id="@ id/loginText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/_15sdp"
android:fontFamily="sans-serif-medium"
android:text="TextView"
android:textAlignment="center"
android:textColor="#FFFFFF00"
android:textSize="@dimen/_18ssp"
app:layout_constraintBottom_toBottomOf="@ id/infoText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@ id/logo" />
<TextView
android:id="@ id/infoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:text="Poniżej znajdziesz informacje o swoim koncie i o serwerze"
android:textAlignment="center"
android:textSize="@dimen/_11ssp"
app:layout_constraintBottom_toTopOf="@ id/guideline7"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@ id/loginText" />
<ImageView
android:id="@ id/imageView4"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="@dimen/_5sdp"
android:layerType="software"
app:layout_constraintBottom_toTopOf="@ id/guideline7"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@ id/infoText"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="@drawable/dotted" />
<androidx.constraintlayout.widget.Guideline
android:id="@ id/guideline8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="838dp"
app:layout_constraintGuide_percent="1.0" />
<ScrollView
android:id="@ id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
tools:ignore="SpeakableTextPresentCheck">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:addStatesFromChildren="true"
android:clipChildren="true">
<ImageView
android:id="@ id/imageView7"
android:layout_width="@dimen/_440sdp"
android:layout_height="@dimen/_150sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@ id/guideline7"
app:srcCompat="@drawable/stats_bg"
tools:ignore="NotSibling"
tools:layout_editor_absoluteY="278dp" />
<ImageView
android:id="@ id/imageView8"
android:layout_width="@dimen/_440sdp"
android:layout_height="@dimen/_150sdp"
android:layout_marginTop="@dimen/_15sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@ id/imageView7"
app:srcCompat="@drawable/punish_bg"
tools:ignore="NotSibling" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
My XML Code Result (Can't scroll images and images are in weird position):

CodePudding user response:
You need to constrain your scrollView
<ScrollView
android:id="@ id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@ id/imageView4"
android:fillViewport="true"
tools:ignore="SpeakableTextPresentCheck">
CodePudding user response:
Try this:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Your.Top.Views
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<Your.Child.Views
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
</LinearLayout>
What is the parent layout is not important, I just copied from my code. The focus is set the ScrollView' s height to 0 and make it fill the remaining height.
CodePudding user response:
try this...
<androidx.constraintlayout.widget.ConstraintLayout 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/bg"
android:theme="@style/Theme.PlayRPGMobile"
tools:context=".DashActivity">
<ImageView
android:id="@ id/logo"
android:layout_width="0dp"
android:layout_height="@dimen/_32sdp"
android:layout_marginTop="@dimen/_32sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@ id/guideline6"
app:srcCompat="@drawable/logo" />
<androidx.constraintlayout.widget.Guideline
android:id="@ id/guideline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="20dp"
app:layout_constraintGuide_percent="0.0" />
<androidx.constraintlayout.widget.Guideline
android:id="@ id/guideline7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="20dp"
app:layout_constraintGuide_percent="0.3" />
<TextView
android:id="@ id/loginText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/_15sdp"
android:fontFamily="sans-serif-medium"
android:text="TextView"
android:textAlignment="center"
android:textColor="#FFFFFF00"
android:textSize="@dimen/_18ssp"
app:layout_constraintBottom_toBottomOf="@ id/infoText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@ id/logo" />
<TextView
android:id="@ id/infoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:text="Poniżej znajdziesz informacje o swoim koncie i o serwerze"
android:textAlignment="center"
android:textSize="@dimen/_11ssp"
app:layout_constraintBottom_toTopOf="@ id/guideline7"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@ id/loginText" />
<ImageView
android:id="@ id/imageView4"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="@dimen/_5sdp"
android:layerType="software"
app:layout_constraintBottom_toTopOf="@ id/guideline7"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@ id/infoText"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="@drawable/dotted" />
<androidx.constraintlayout.widget.Guideline
android:id="@ id/guideline8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="838dp"
app:layout_constraintGuide_percent="1.0" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:addStatesFromChildren="true"
android:clipChildren="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@ id/imageView4">
<ScrollView
android:id="@ id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@ id/imageView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@ id/guideline7"
app:srcCompat="@drawable/stats_bg"
tools:ignore="NotSibling"
tools:layout_editor_absoluteY="278dp" />
<ImageView
android:id="@ id/imageView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/imageView7"
android:layout_marginTop="@dimen/_15sdp"
app:srcCompat="@drawable/punish_bg"
tools:ignore="NotSibling" />
</RelativeLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

