Android 如何更改scrollView中的视图位置,将其固定在屏幕顶部
我有一个scrollview,在scrollview中我有一些项目,我想根据scrollview scrollY将其中一些项目固定到屏幕顶部(如stickyheaderListview)。我几乎什么都试过了 若我将标题项Y位置设置为零,它会改变位置,但在这之后,它是scrollView中的第一项Android 如何更改scrollView中的视图位置,将其固定在屏幕顶部,android,listview,scrollview,Android,Listview,Scrollview,我有一个scrollview,在scrollview中我有一些项目,我想根据scrollview scrollY将其中一些项目固定到屏幕顶部(如stickyheaderListview)。我几乎什么都试过了 若我将标题项Y位置设置为零,它会改变位置,但在这之后,它是scrollView中的第一项 header.animate().y(0).setDuration(0).start(); // first attempt header.setTop(0); // second attempt he
header.animate().y(0).setDuration(0).start(); // first attempt
header.setTop(0); // second attempt
header.animate().y(mScrollView.getLastItem().getBottom).setDuration(0).start();// third attempt
p.S
我的目标是在scrollView中创建stickyheader列表项
我在scrollview中尝试过这个,但它不起作用,所有项目通常都是滚动的嗯,我认为在Android中可能有多种方法来实现相同的UI 1) 第一种方式,将滚动视图包装成如下相对布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="top here"
android:id="@+id/text"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sample"
/>
</ScrollView>
</RelativeLayout>
2) 或者另一种方法是,您可以将主布局分成两个片段,一个片段显示始终位于顶部的视图,另一个片段将加载scrollview的内容
3) 这篇文章可能是你的一个很好的参考