【问题标题】:Scroll from a particular element to the end [Android]从特定元素滚动到末尾 [Android]
【发布时间】:2016-08-14 13:21:02
【问题描述】:

所以,我正在尝试构建这个具有 2 个列表视图和一个网格视图的屏幕,我想要的是,一旦我开始在底部列表视图上滚动,它应该向上移动所有元素并滚动,而不是单独滚动。 Screenshot of Layout

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >


<ListView
    android:id="@+id/listview1"
    android:layout_width="fill_parent"
    android:layout_height="200sp" />

<GridView
    android:numColumns="auto_fit"
    android:gravity="center"
    android:columnWidth="100dp"
    android:stretchMode="columnWidth"
    android:layout_width="fill_parent"
    android:layout_height="110sp"
    android:id="@+id/grid"
    android:horizontalSpacing="5dp"
    android:verticalSpacing="-27dp"
    android:layout_below="@+id/listview1"
    android:layout_weight="0.37" />
        <ListView
            android:layout_width="wrap_content"
            android:layout_height="500dp"
            android:id="@+id/lvScribe"
            android:layout_below="@+id/grid" />
<com.ashokvarma.bottomnavigation.BottomNavigationBar
    android:layout_gravity="bottom"
    android:id="@+id/bottom_navigation_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />




</RelativeLayout>

【问题讨论】:

    标签: android xml android-layout listview


    【解决方案1】:

    假设您知道列表数据何时发生更改,您可以通过将列表选择设置为最后一行来手动告诉列表滚动到底部。 请根据您的要求使用此代码

    private void scrolListView() {
        myListView.post(new Runnable() {
            @Override
            public void run() {
                // Select the last row so it will scroll into view...
                myListView.setSelection(myListAdapter.getCount() - 1);
            }
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-10
      • 1970-01-01
      • 2021-09-11
      • 1970-01-01
      • 2017-07-09
      • 2019-03-18
      • 2016-01-17
      • 1970-01-01
      相关资源
      最近更新 更多