java - Android滚动到滚动视图中的下一个替换片段顶部
问题描述
这是我的布局:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_scrollview"
android:layout_width="match_parent"
android:scrollbars="vertical"
android:fillViewport="true"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/space.small"
android:orientation="vertical"
android:padding="@dimen/space.medium">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/space.medium">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bla_bla_bla"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/my_relative_layout">
</RelativeLayout>
</LinearLayout>
</ScrollView>
它是我的选项卡菜单中的一个片段,当创建此选项卡时,相对布局将被可变数量的元素替换:
android.support.v4.app.FragmentTransaction ft = getChildFragmentManager().beginTransaction();
ft.replace(R.id.my_relative_layout, myListFragment).commit();
mHolder.scrollView.scrollTo(0,0); //not work
但是我的片段不会滚动到顶部,它只能在延迟时起作用,例如:
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mHolder.scrollView.scrollTo(0,0);
}
}, 100);
我怎样才能以正确的方式做到这一点?我不会使用延迟
解决方案
添加
android:descendantFocusability="blocksDescendants"
到
"RelativeLayout"
推荐阅读
- image-processing - Remove color cast using libvips
- excel - Sumproduct - 计算相等的数字对(并过滤它们)
- docker - 如何从 docker-compose.yml 中的私有 docker 存储库中提取 docker 映像?
- mongodb - 将字段名称映射到猫鼬中的不同模式字段名称
- ms-access - 我在 Power BI 中的表格视觉对象未显示所有数据
- regex - 用于查找文件路径的 Groovy 模式或正则表达式
- java - 我试图清除二维数组的所有值
- python - 使用 OpenCV 创建和保存 16 位 RGB 图像
- django - 从输出中删除查询集
- python - 在 Cython 中将 C++ 向量转换为 numpy 数组而不复制