您好,我在 Android Studio 中制作了我的第一個應用程式。我閱讀了很多關于我的問題的主題,但仍然沒有找到解決方案。每個主題和視頻都是關于 ScrollView 作為應用程式的“視圖”。我只想滾動螢屏的一部分(選定部分)

我應該怎么做才能達到我想要的效果?
我的 XML 代碼
<?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>
我的 XML 代碼結果(無法滾動影像并且影像位置很奇怪):

uj5u.com熱心網友回復:
你需要約束你的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">
uj5u.com熱心網友回復:
試試這個:
<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>
什么是父布局并不重要,我只是從我的代碼中復制過來的。焦點將 ScrollView 的高度設定為 0 并使其填充剩余高度。
uj5u.com熱心網友回復:
試試這個...
<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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/423135.html
標籤:
上一篇:滑行不顯示影像
