Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom ListView with Pinned Header , causing Jank when setting padding

I have a custom listView which contains one pinned header, and x amounts of "push-up" views, which can be pushed up and hidden above the list view.

I have attached image to explain them. Sorry for the "black censorship", just to hide customers logo etc.

My problem is that if I add a padding to the pinned Header view, I will get the listview items floating behind it.

The pinned header view, is implemented with the same technique as you'll find if you search for PinnedHeaderListView , that is, a static view and a Header in the listview.

I have a found a way to enable padding, and that is by applying the same padding as the pinned header, to the actual listView, but only when the static header is visible.

However, the calling of setPadding causes a quite visible Jank which I would like to remove. Does anyone have any idea how to remove this jank?

I have a simple application with simple views and dummy data, which does not show this jank, so maybe the amount of jank depends on the complexity of cell layouts.

private void updateIfShouldShowStaticHeaderView() {

    //unfortunately setting the padding of the listView causes JANK.

    //any ideas?
    int bottomOfFloatingHeader = floatingHeader.getBottom();
    if (bottomOfFloatingHeader < mHeaderViewHeight) {
        staticHeaderViewIsVisible = true;
        staticHeader.setVisibility(View.VISIBLE);

        //need to set padding of listView to avoid having list-view items float behind my padded static header
        setPadding(0, staticHeader.getPaddingTop(), 0, getPaddingBottom());
    } else {
        staticHeaderViewIsVisible = false;
        staticHeader.setVisibility(View.INVISIBLE);
        //need to set padding of listView to avoid having list-view items float behind my padded static header
        setPadding(0, 0, 0, getPaddingBottom());
    }
}

First here is the image showing the pushed-up headers showing the pushed-up headers

Here is an image showing how things get drawn behind the padded static pinned view. It is worth noticing that it works as intented if I adjust the padding of the listView, but I will get Jank (slowdown) , at the time it switches on/off the static header view.

showing the error that is visible if I do not adjust padding

like image 980
havchr Avatar asked Jul 12 '12 12:07

havchr


1 Answers

Need some more info over your question.

With my understanding Jank is due to huge amount of data and drawable that you are using.

Try to enable hardware acceleration for your view.

For more about HW acceleration try this http://developer.android.com/guide/topics/graphics/hardware-accel.html

like image 143
Ajay Kumar Meher Avatar answered Nov 01 '22 07:11

Ajay Kumar Meher