我在Android Studio中一個初學者,Android開發一般。我希望滾動視圖只允許滾動直到圖像的結尾,但滾動到空白區域。我嘗試了很多東西,但是我只是沒有弄清楚我錯了什麼。如何限制滾動圖像(滾動視圖)到空白區域?
The scrollable image, Image showing scrolling into the white space
下面是XML代碼:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:overScrollMode="never"
tools:context="com.android101.chroniclesofnarutouzumaki.MainActivity">
<RelativeLayout
android:id="@+id/relative_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:src="@drawable/naruto_uzumaki"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:id="@+id/naruto" />
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:text="Never Give Up!" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/text1"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:layout_marginTop="438dp"
android:text="What to Add?" />
</RelativeLayout>
</ScrollView>
這得到了圓滿解決。在imageview中添加了'android:adjustViewBounds =「true」'。 –