2017-09-29 14 views
1

enter image description here 나는 stickyheaderlistview (lib)에서 첫 번째 보이는 헤더를 페이드 아웃하고 싶습니다. 목록보기에서 첫 번째로 보이는 머리글을 어떻게 페이드 아웃합니까? 몇 가지 예를 들어주세요. 고맙습니다. 당신이 날짜 헤더를 관찰하면 약간의 시간whatsapp와 같은리스트 뷰에서 헤더를 fadeout하는 방법

+1

시도해 본 내용이 있습니까? –

+0

https://github.com/ksoichiro/Android-ObservableScrollView –

+0

마침내 스크롤 유휴 상태에서 false로 setAreHeadersSticky가 수행되었습니다. 감사합니다. –

답변

1

컴파일이 후 사용자 상호 작용이없는 경우는 숨길 수 : 어댑터에서

compile 'se.emilsjolander:stickylistheaders:2.1.3' 

public class ChatAdapter extends BaseAdapter implements StickyListHeadersAdapter { 

    private Activity mActivity; 
    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); 
    private SimpleDateFormat dateformat = new SimpleDateFormat("hh:mm a"); 
    private SimpleDateFormat format1 = new SimpleDateFormat("ddMMyyyy"); 
    private SimpleDateFormat headerdateformat = new SimpleDateFormat("dd MMMM yyyy"); 
    private Date date = null; 
    private String msgDate = ""; 
    private Date headerDate = null; 
    private String msgHeader = ""; 
    private String msg = ""; 
    private String mName = ""; 
    private int day = 0; 
List<GroupChatHistoryData> mChatArrayList = new ArrayList<>(); 

    public ChatAdapter(Activity mActivity,List<GroupChatHistoryData> mChatArrayList) { 
     this.mActivity = mActivity; 
this.mChatArrayList = mChatArrayList; 
    } 

    @Override 
    public int getCount() { 
     return mChatArrayList.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return mChatArrayList.get(position); 
    } 

    @Override 
    public long getItemId(int position) { 
     return position; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     final ViewHolder holder; 

     if (convertView == null) { 

      LayoutInflater inflater = (LayoutInflater) mActivity. 
        getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      /****** Inflate tabitem.xml file for each row (Defined below) *******/ 
      convertView = inflater.inflate(R.layout.chat_details_row_item, null); 

      holder = new ViewHolder(); 

      holder.receive_message_text = (TextView) convertView.findViewById(R.id.receive_message_text); 
      holder.receive_message_date = (TextView) convertView.findViewById(R.id.receive_message_date); 
      holder.receive_member_name = (TextView) convertView.findViewById(R.id.receive_member_name); 
      holder.sent_message_date = (TextView) convertView.findViewById(R.id.sent_message_date); 
      holder.sent_message_text = (TextView) convertView.findViewById(R.id.sent_message_text); 

      holder.chat_receive_layout = (LinearLayout) convertView.findViewById(R.id.chat_receive_layout); 
      holder.sent_msg_ll = (LinearLayout) convertView.findViewById(R.id.sent_msg_ll); 

      convertView.setTag(holder); 
     } else { 
      holder = (ViewHolder) convertView.getTag(); 
     } 

     final GroupChatHistoryData bean = mChatArrayList.get(position); 

     try { 
      if (bean.getTime() != null && !bean.getTime().equalsIgnoreCase("")) { 
       date = format.parse(bean.getTime()); 
      } 
     } catch (ParseException e) { 
      e.printStackTrace(); 
     } 
     if (date != null) { 
      msgDate = dateformat.format(date); 
     } 

     msg = bean.getMessage(); 


// your rest views 

     return convertView; 
    } 


    @Override 
    public View getHeaderView(int position, View convertView, ViewGroup parent) { 
     final HeaderViewHolder holder; 
     LayoutInflater inflater = LayoutInflater.from(mActivity); 
     if (convertView == null) { 
      convertView = inflater.inflate(R.layout.chat_header, parent, false); 
      holder = new HeaderViewHolder(); 

      holder.headerDate = (TextView) convertView.findViewById(R.id.header_date); 

      convertView.setTag(holder); 

     } else { 
      holder = (HeaderViewHolder) convertView.getTag(); 
     } 

     GroupChatHistoryData bean = mChatArrayList.get(position); 

     try { 
      if (bean.getDatetime() != null && !bean.getDatetime().equalsIgnoreCase("")) { 
       headerDate = format1.parse(bean.getDatetime()); 
      } 
     } catch (ParseException e) { 
      e.printStackTrace(); 
     } 

     if (headerDate != null) { 
      msgHeader = headerdateformat.format(headerDate); 
     } 

     if (show(msgHeader) == 0) { 
      holder.headerDate.setText("TODAY"); 
     } else if (show(msgHeader) == -1) { 
      holder.headerDate.setText("YESTERDAY"); 
     } else { 
      holder.headerDate.setText(msgHeader); 
     } 

     return convertView; 
    } 

    private class HeaderViewHolder { 
     private TextView headerDate; 
    } 

    @Override 
    public long getHeaderId(int position) { 
     String mDate = mChatArrayList.get(position).getDatetime(); 
     int mDatePos = Integer.parseInt(mDate); 
     return mDatePos; 
    } 

    private class ViewHolder { 
     TextView receive_message_text; 
     TextView receive_message_date; 
     TextView receive_member_name; 
     TextView sent_message_date; 
     TextView sent_message_text; 

     LinearLayout chat_receive_layout; 
     LinearLayout sent_msg_ll; 
    } 

    private int show(String time) { 
     try { 
      String outputPattern = "dd MMMM yyyy"; 
      SimpleDateFormat format = new SimpleDateFormat(outputPattern); 

      Date Date1 = format.parse(getdate()); 
      Date Date2 = format.parse(time); 
      long mills = Date2.getTime() - Date1.getTime(); 
      long Day1 = mills/(1000 * 60 * 60); 

      day = (int) Day1/24; 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return day; 
    } 


    private String getdate() { 
     String time = ""; 
     try { 
      String outputPattern = "dd MMMM yyyy"; 

      Calendar c = Calendar.getInstance(); 
      SimpleDateFormat df = new SimpleDateFormat(outputPattern); 
      time = df.format(c.getTime()); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return time; 
    } 

} 

chat_header.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp"> 

     <TextView 
      android:id="@+id/header_date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:background="#BDD9E4" 
      android:gravity="center" 
      android:padding="10dp" 
      android:textAllCaps="true" 
      android:textSize="12sp" 
      android:textColor="@color/gray" 
      android:textStyle="bold" /> 

    </RelativeLayout> 

</RelativeLayout> 

GroupChatHistoryData 빈은 다음과 같습니다.

public class GroupChatHistoryData { 


    private SimpleDateFormat headerdateformat = new SimpleDateFormat("ddMMyyyy"); 
    private Date headerDate = null; 
    private Date mTime = null; 
    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); 
    private SimpleDateFormat timeformat = new SimpleDateFormat("hh:mm a"); 

    @SerializedName("user_id") 
    @Expose 
    private String userId; 
    @SerializedName("group_id") 
    @Expose 
    private String groupId; 
    @SerializedName("message") 
    @Expose 
    private String message; 
    @SerializedName("datetime") 
    @Expose 
    private String datetime; 
    @SerializedName("fname") 
    @Expose 
    private String fname; 
    @SerializedName("time") 
    @Expose 
    private String time; 

    public String getUserId() { 
     return userId; 
    } 

    public void setUserId(String userId) { 
     this.userId = userId; 
    } 

    public String getGroupId() { 
     return groupId; 
    } 

    public void setGroupId(String groupId) { 
     this.groupId = groupId; 
    } 

    public String getMessage() { 
     return message; 
    } 

    public void setMessage(String message) { 
     this.message = message; 
    } 

    public String getDatetime() { 

     String date = ""; 
     try { 
      if (datetime != null && !datetime.equalsIgnoreCase("")) { 
       headerDate = format.parse(datetime); 
      } 
     } catch (ParseException e) { 
      e.printStackTrace(); 
     } 
     if (headerDate != null) { 
      date = headerdateformat.format(headerDate); 
     } 

     return date; 
    } 

    public void setDatetime(String datetime) { 
     this.datetime = datetime; 
    } 

    public String getFname() { 
     return fname; 
    } 

    public void setFname(String fname) { 
     this.fname = fname; 
    } 


    public boolean isMine() { 
     return isMine; 
    } 

    public void setMine(boolean mine) { 
     isMine = mine; 
    } 

    public boolean isMine = false; 

    public String getTime() { 

     return time; 
    } 

    public void setTime(String time) { 
     this.time = time; 
    } 

} 
+0

안녕 Maroof, 끈적한 헤더를 표시 할 수 있지만 내 문제는 사용자가 스크롤 할 때 헤더 가시성을 전환하는 것입니다. whatsapp와 같은 스크롤을 멈 춥니 다. thank u –

+1

예, 여기서 공유 한 코드는 req (whatsapp와 동일)와 동일하게 수행합니다. 내 코드를 시도 했니? – Maroof

+0

이 라이브러리는 더 이상 사용되지 않습니다 –