我有两个线性布局的 GridView 。这是我的 XML 代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<GridView
android:id="@+id/leftGrid2"
android:layout_width="416dp"
android:layout_height="1078dp"
android:columnWidth="70dp"
android:horizontalSpacing="5dp"
android:numColumns="2"
android:paddingRight="20dp"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp" >
</GridView>
<GridView
android:id="@+id/rightGrid2"
android:layout_width="400dp"
android:layout_height="match_parent"
android:columnWidth="70dp"
android:horizontalSpacing="5dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp" >
</GridView>
</LinearLayout>
如何使这两个 GridView 一起滚动或同步?当我运行我的应用程序时,它们有两个单独的卷轴。
谢谢
最佳答案
GridView 提供 smoothScrollToPosition(int)方法通过其 AbsLisView 父级。这将滚动到您想要的位置。现在,您使用 OnScrollListener 监听 ScrollEvent 。现在只需将它们绑在一起:
GridView other;
@Override public void onScroll(AbsListView view, int firstItem, int visItems, int total) {
other.smoothScrollToPosition(firstItem);
}
现在,如果您的两个 View 不具有可比性,则这不会!按预期工作。内容数量相同。
关于android - 如何在线性布局中一起滚动 2 个 GridView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11549613/