Android listview extra space at the end when scrolling

I experienced weird behavior with smooth scrolling in the list. I have 30 items in the list. When I smooth the scroll through

listview.smoothScrollToPositionFromTop(29, 0);

additional space appears at the end of the screen. Actually the list is browsed a little. The image is attached below. But if I scroll manually, there will be no space. What can be done to allow this behavior?

Image 1

Here is my layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_orange_light">

<ListView
    android:id="@+id/listview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</RelativeLayout>
+6
source share
7 answers

, , Android. , , , , "" . SwipeToRefresh, .

, ,

    listView.setOverScrollMode(View.OVER_SCROLL_NEVER);

, , . , , .

AbsListView # setOverScrollMode (int)

: ( , )

. . , . , - , . 1, . , , . , .

    Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.invisible_footer, null);
    listView.setOverscrollFooter(drawable);

"invisible_footer.xml"

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:height="2dp"
    android:width="10dp"

    android:viewportWidth="10"
    android:viewportHeight="2">

    <!-- a horizontal line -->
    <path android:pathData="M 1 1 H 10"
        android:strokeColor="#00000000" android:strokeWidth="1" />

</vector>

ListView.html # setOverscrollHeader()

:

  • , 1
+3

. , .

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.socialintegration.ListAct">
<ListView
    android:id="@+id/listTemp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"></ListView>

</RelativeLayout>

:

public class ListAct extends AppCompatActivity {
ListView l;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    String str[] = new String[50];
    for (int i = 0; i < 50; i++) {
        str[i] = "poistion" + i;
    }
    ArrayAdapter adpt = new ArrayAdapter(ListAct.this, android.R.layout.simple_dropdown_item_1line, str);
    l = (ListView) findViewById(R.id.listTemp);
    l.setAdapter(adpt);

    l.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            l.smoothScrollToPositionFromTop(29, 0);
        }
    });
}
}
+1
<ListView>
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  app:layout_behavior="@string/appbar_scrolling_view_behavior/>

, : : layout_behavior = "@/appbar_scrolling_view_behavior"

0

ListView wrap_content match_parent?

wrap_content. ListView :

<ListView
    android:id="@+id/listview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
0

SO post . , .

0

I firmly believe that I will go to RecyclerView. If you do not want to move. Here is the work. Just add this method to your activity and name it.

private void smoothScrollToTop(final int pos) {
    listView.smoothScrollToPositionFromTop(pos, 0);
    listView.post(new Runnable() {
        @Override
        public void run() {
            listView.smoothScrollToPosition(pos);
        }
    });
}

This is well tested. and worked for me. And here it is deduced.

enter image description here

0
source

try this for your xml:

<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:clipToPadding="false"/>
0
source

Source: https://habr.com/ru/post/1015398/


All Articles