java - Android 在同一页面上滚动到 ID

标签 java android android-layout

我在谷歌上搜索了一个关于在同一页面上按 ID 滚动到元素的示例,但没有成功。我想知道如何使用以下示例完成它?

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
       android:layout_width="fill_parent"
       android:layout_height="fill_parent" >

    <Button 
       android:id="@+id/pressMe"
       android:layout_height="wrap_content"
       android:layout_width="wrap_content"
       android:text="Press me to scroll to A">

    <ImageView
       android:id="@+id/scrollToMe"
       android:layout_height="100dp"
       android:layout_width="fill_parent"
       android:layout_marginTop="2000dp"
       android:background="#f00">

    </LinearLayout>

</ScrollView>

最佳答案

您可以专注于该 View ,我认为它会自动滚动到该 View 。

我相信您还可以获得所需 View 的坐标并滚动到它们。

关于java - Android 在同一页面上滚动到 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11082047/

相关文章:

java - HashMap同步

java - 如何减少创建 c3p0 ComboPooledDataSource 和获取 Oracle 数据库连接的超时时间?

android - TextInputLayout 密码切换从中心移动文本

android - INSTALL_FAILED_INSUFFICIENT_STORAGE 运行 npm run android 命令时出错

android - 以编程方式删除方向限制

android - 如何设置最大值edittext 控件中的文本长度

java - JAXB ClassNotFoundException 使用 Java 11 构建 Spring Boot App 2.2.0

java - Cassandra docker - 无法通过 JMX 连接

android - 如何下载 Rev. 9 第三方插件?

java - 一些 Recyclerview 项目相互影响