【发布时间】:2022-12-12 06:22:20
【问题描述】:
Udacity 的课程 Developing Android Apps with Kotlin,布局部分,大致为 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"
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">
<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>
目标是显示名称、名称下方的星号以及下方的可滚动描述。当文本足够短以适合无需滚动时,这就是外观:
但是当文本足够长需要滚动时,可滚动区域似乎将其他组件移出了视图:
这门课程有点老了,所以也许有些东西已经改变了,或者我应用的东西不正确。需要更改什么才能使 ScrollView 保持在其范围内?
【问题讨论】:
-
如果我没有弄错的话,你是说名称和图像也会随着可滚动内容一起滚动,对吗?
-
@Bhavnik 它似乎没有滚动-上下滚动文本时根本不显示名称。星不动。