Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7814137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:06:05+00:00 2026-06-02T05:06:05+00:00

How can i implement custom section or header of ListView like Instagram app in

  • 0

How can i implement custom section or header of ListView like Instagram app in android.

http://prsarahevans.com/wp-content/uploads/2011/06/photo.PNG

When scroll up the bar that have userpic, name and time still be there and when other header bar go near it then animate like push it up.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:06:07+00:00Added an answer on June 2, 2026 at 5:06 am

    I was able to solve this issue by using scroll listener on the listview. (tested on 2.1)

    Lets say for each list row I have a layout like the one below. There is a content part and a header part. It doesn’t matter what view type you use for header or content.

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" android:background="#FFFFFF">
    
        <ImageView
            android:id="@+id/content"
            android:layout_width="fill_parent"
            android:layout_height="300dp"
            android:scaleType="centerCrop" 
            android:src="@drawable/pic"
            android:background="#aaaaff" 
            android:layout_marginTop="40dp"/>
    
        <TextView
            android:id="@+id/header"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:padding="12dp"
            android:text="Deneme Row"
            android:textColor="#000000" 
            android:background="#99ffffff"/>
    </RelativeLayout>
    

    The test layout for the activity is as in the following:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
        </ListView>
    </LinearLayout>
    

    Finally the code for the activity is given below. Here I had to have an adapter which uses ViewHolder to store the header view and also a variable to keep track of the change in the scroll for each successive scroll events (previousTop). This is because of the fact that offsetTopAndBottom() changes offset of the view related to the previous location of it.

    public class TestActivity extends Activity implements AbsListView.OnScrollListener{
    
        ListView list; 
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            list = (ListView) findViewById(R.id.list);
            list.setAdapter(new Adapter(this));        
            list.setOnScrollListener(this); 
        }
    
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {     
            //the listview has only few children (of course according to the height of each child) who are visible
            for(int i=0; i < list.getChildCount(); i++){
                View child = list.getChildAt(i);
                ViewHolder holder = (ViewHolder) child.getTag();
    
                //if the view is the first item at the top we will do some processing
                if(i == 0){             
                    boolean isAtBottom = child.getHeight() <= holder.header.getBottom();
                    int offset = holder.previousTop - child.getTop();
                    if(!(isAtBottom && offset > 0)){                    
                        holder.previousTop = child.getTop();
                        holder.header.offsetTopAndBottom(offset);                   
                        holder.header.invalidate();
                    }
                } //if the view is not the first item it "may" need some correction because of view re-use
                else if (holder.header.getTop() != 0) {
                    int offset = -1 * holder.header.getTop(); 
                    holder.header.offsetTopAndBottom(offset);
                    holder.previousTop = 0;
                    holder.header.invalidate();
                }
            }
        }
    
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {}
    
        private static class Adapter extends ArrayAdapter<String> {
            public Adapter(Context context) {
                super(context, R.layout.row, R.id.header);
                for(int i=0; i < 50; i++){
                    add(Integer.toString(i));
                }
            }
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                if(convertView == null){
                    convertView = LayoutInflater.from(getContext()).inflate(R.layout.row, parent, false);
                    ViewHolder holder = new ViewHolder();
                    holder.header = (TextView) convertView.findViewById(R.id.header);
                    convertView.setTag(holder);             
                }
                ViewHolder holder = (ViewHolder) convertView.getTag();
                holder.header.setText(getItem(position));
                return convertView;
            }
        }
    
        private static class ViewHolder {
            TextView header;
            int previousTop = 0;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I implement a custom swipe animation instead of the standard horizontal movement?
I'd like to know if I can implement a method on MemoryCache that removes
I have a news table and I would like to implement custom ordering. I
I have a UITextField in a custom section header. There are multiple sections using
How can I implement role based custom user authentication in asp.net MVC 3. Consider
Is there a way to implement custom data detectors in NSTextView (like the one
I would like for my section header to display the sum of the values
I am trying to implement a custom configuration section in a project and I
How can implement reordring in winforms datagridview by using the feature of drag and
Can someone please tell me how I can implement the following line of pseudo-code.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.