【发布时间】:2020-03-11 14:52:07
【问题描述】:
我有一个小问题。我在带有TextViews的布局scrollView中,现在我必须设置按钮以向上滚动scrollView,但我不知道如何在我的布局中设置好imageButton。这是我的架构。
我必须将这个 imageButton 设置到位,我在模式中显示,TextView5 非常长,当它开始滚动时,imageButton 应该开始可见,在滚动之前它应该是不可见的。
要向上滚动,我正在使用代码:
buttonScrollTop.setOnClickListener {
scrollView.fullScroll(ScrollView.FOCUS_UP)
}
我的xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="@color/colorBackgroundWhite">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<TextView
android:id="@+id/TextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:ellipsize="end"
android:gravity="center"
android:text="@string/text1" />
<TextView
android:id="@+id/TextView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:ellipsize="end"
android:gravity="center"
android:paddingBottom="8dp"
android:text="@string/text2" />
<TextView
android:id="@+id/TextView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/text3"/>
<TextView
android:id="@+id/TextView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:justificationMode="inter_word"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:text="@string/text4" />
<TextView
android:id="@+id/TextView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:justificationMode="inter_word"
android:ellipsize="end"
android:text="@string/bigstringtext5" />
<ImageButton
android:id="@+id/buttonScrollTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@android:drawable/ic_menu_upload" />
<TextView
android:id="@+id/TextView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:justificationMode="inter_word"
android:ellipsize="end"
android:gravity="center"
android:text="@string/text6" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
但现在 imageButton 在 TextView5 下;/ 我不知道如何在模式中设置它。 感谢您的帮助:)
【问题讨论】:
-
在
ScrollView之外的父布局 (RelativeLayout) 中使用ImageButton和alignParentBottom="true"和alignParentEnd="true",然后给您的 ImageButton 边距以使其完美。 -
它可以工作,但不要让它在开始时不可见,你知道如何让它在开始时不可见并在开始滚动时可见吗? :)