开发者

ScrollView exceeding bounds of LinearLayout

Udacity's course Developing Android Apps with Kotlin, the Layouts section, offers roughly this for activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.widget.LinearLayout 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="wrap_content"
    android:orientation="vertical"
    android:paddingStart="@dimen/padding"
    android:paddingEnd="@dimen/padding">

    <TextView
        android:id="@+id/textView"
        style="@style/NameStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/name_text" />

    <ImageView
        android:id="@+id/star_image"
        a开发者_如何转开发ndroid:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:contentDescription="@string/star_description"
        app:srcCompat="@android:drawable/btn_star_big_on"
        tools:ignore="ImageContrastCheck" />

    <ScrollView
        android:id="@+id/bio_scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/bio_text"
            style="@style/NameStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:lineSpacingMultiplier="1.2"
            android:text="@string/bio" />
    </ScrollView>
</android.widget.LinearLayout>

The goal is to show a name, a star below it, and a scrollable description below that. When the text is short enough to fit without scrolling, this is the appearance:

ScrollView exceeding bounds of LinearLayout

But when the text is long enough to require scrolling, the scrollable area seems to move other components out of view:

ScrollView exceeding bounds of LinearLayout

The course is a little old, so perhaps some things have changed, or perhaps I applied things incorrectly. What needs to be changed so the ScrollView stays within its bounds?


//Copy and paste this

   <?xml version="1.0" encoding="utf-8"?>
        <android.widget.LinearLayout 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="wrap_content"
            android:orientation="vertical"
            android:paddingStart="@dimen/padding"
            android:paddingEnd="@dimen/padding">
        
            <TextView
                android:id="@+id/textView"
                style="@style/NameStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/name_text" />
        
            <ImageView
                android:id="@+id/star_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:contentDescription="@string/star_description"
                app:srcCompat="@android:drawable/btn_star_big_on"
                tools:ignore="ImageContrastCheck" />
        
            <ScrollView
                android:id="@+id/bio_scroll"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
       < RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        
                <TextView
                    android:id="@+id/bio_text"
                    style="@style/NameStyle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:lineSpacingMultiplier="1.2"
                    android:text="@string/bio" />
    </RelativeLayout>
            </ScrollView>
        </android.widget.LinearLayout>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜