亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

listview添加標題并且懸停頂部

2019-11-09 14:57:27
字體:
來源:轉載
供稿:網友

給listview添加標題并且隨著手勢的滑動標題可以懸停在屏幕頂部,效果圖如下:

效果實現起來也不是很復雜,需要自定義listview,答題的思路就是自定義的listview頂部有個textview的title,適配器的頂部也有一個,當滿足一定條件的時候標題變化,

/*** * 帶標題的listview *  * @author zhang *  */public class TitledListView extends ListView {	PRivate View mTitle;	TextView title_text;	public static boolean FLAG_VIEW;// 隱藏title標識,true:gone ; false:visibile(如果要不顯示標題,改值一定要在刷新適配器值前調用)	public TitledListView(Context context) {		super(context);	}	public TitledListView(Context context, AttributeSet attrs) {		super(context, attrs);	}	public TitledListView(Context context, AttributeSet attrs, int defStyle) {		super(context, attrs, defStyle);	}	@Override	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {		super.onMeasure(widthMeasureSpec, heightMeasureSpec);		if (mTitle != null) {			measureChild(mTitle, widthMeasureSpec, heightMeasureSpec);		}	}	@Override	protected void onLayout(boolean changed, int l, int t, int r, int b) {		super.onLayout(changed, l, t, r, b);		if (mTitle != null) {			mTitle.layout(0, 0, mTitle.getMeasuredWidth(), mTitle.getMeasuredHeight());		}	}	@Override	protected void dispatchDraw(Canvas canvas) {		super.dispatchDraw(canvas);		if (FLAG_VIEW) {			mTitle.setVisibility(View.GONE);		} else {			if (mTitle != null) {				drawChild(canvas, mTitle, getDrawingTime());			}		}	}	@Override	public void setAdapter(ListAdapter adapter) {		super.setAdapter(adapter);		LayoutInflater inflater = LayoutInflater.from(getContext());		mTitle = inflater.inflate(R.layout.title, this, false);		title_text = (TextView) mTitle.findViewById(R.id.titled_text);	}	public void moveTitle(String title) {		View bottomChild = getChildAt(0);		if (bottomChild != null) {			int bottom = bottomChild.getBottom();			int height = mTitle.getMeasuredHeight();			int y = 0;			if (bottom < height) {				y = bottom - height;			}			if (title != null) {				title_text.setText(title);			}			mTitle.layout(0, y, mTitle.getMeasuredWidth(), mTitle.getMeasuredHeight() + y);		}	}	public void updateTitle(String title) {		if (title != null) {			title_text.setText(title);		}		mTitle.layout(0, 0, mTitle.getMeasuredWidth(), mTitle.getMeasuredHeight());	}	public String getTitle() {		return title_text.getText().toString();	}}

主頁面布局:

 <LinearLayout        android:id="@+id/ll_group_hoster"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:background="@color/bg_white"        android:orientation="vertical" >        <com.jingxinlawyer.lawchat.widget.TitledListView            android:id="@+id/lv_group_hoster"            android:layout_width="match_parent"            android:layout_height="fill_parent"            android:cacheColorHint="#00000000" >        </com.jingxinlawyer.lawchat.widget.TitledListView>    </LinearLayout>適配器布局:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@drawable/selector_rl_item"    android:descendantFocusability="beforeDescendants"    android:orientation="vertical" >    <TextView        android:id="@+id/catalog2"        android:layout_width="fill_parent"        android:layout_height="32dp"        android:background="@color/bg_gray"        android:gravity="center_vertical"        android:paddingLeft="@dimen/pdingLeftRight"        android:textColor="@color/text_black" />    <View style="@style/line" />    <RelativeLayout        android:id="@+id/rl_member"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:descendantFocusability="beforeDescendants"        android:padding="10dp" >        <ImageView            android:id="@+id/ivGroupHeader2"            android:layout_width="50dp"            android:layout_height="50dp"            android:layout_alignParentLeft="true"            android:contentDescription="@string/description"            android:scaleType="fitXY" />        <TextView            android:id="@+id/tvGroupName2"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_marginLeft="10dp"            android:layout_toRightOf="@id/ivGroupHeader2"            android:ellipsize="end"            android:maxLength="12"            android:text="name"            android:singleLine="true"            android:textColor="@color/text_black"            android:textSize="@dimen/text_name" />        <TextView            android:id="@+id/tv_kq_no2"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_marginLeft="3dp"            android:layout_toRightOf="@id/tvGroupName2"            android:singleLine="true"            android:layout_toLeftOf="@+id/tvGroupTime2"            android:textColor="@color/text_gray"            android:textSize="@dimen/text_name" />        <LinearLayout            android:id="@+id/llGroupIntroduce"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_alignLeft="@id/tvGroupName2"            android:layout_below="@id/tvGroupName2"            android:gravity="center" >                     <LinearLayout                android:id="@+id/tvGroupSexAge2"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_marginRight="3dp"                android:background="@drawable/shape_sex"                android:gravity="center_vertical"                android:orientation="horizontal"                android:paddingLeft="3dp"                android:paddingRight="3dp" >                <ImageView                    android:id="@+id/iv_sex"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:contentDescription="@string/description"                    android:src="@drawable/qz_nan" />                <TextView                    android:id="@+id/tv_age"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_marginLeft="3dp"                    android:singleLine="true"                    android:textColor="@color/text_white"                    android:textSize="12sp" />            </LinearLayout>            <TextView                android:id="@+id/tvGroupHoster2"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="@drawable/shape_near_lawyer_item"                android:maxLength="12"                android:padding="2dp"                android:singleLine="true"                android:text="律師"                android:textColor="@color/text_pink"                android:textSize="12sp" />            <TextView                android:id="@+id/tvGroupWork2"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_marginLeft="3dp"                android:background="@drawable/shape_near_lawyer_item"                android:maxLength="12"                android:padding="2dp"                android:singleLine="true"                android:text="IT"                android:textColor="@color/text_pink"                android:textSize="12sp" />        </LinearLayout>        <LinearLayout            android:id="@+id/llUserIntroduce"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_alignBottom="@id/ivGroupHeader2"            android:layout_alignLeft="@id/tvGroupName2"            android:layout_below="@id/tvGroupName2"            android:layout_marginRight="30dp"            android:gravity="center"            android:visibility="gone" >            <TextView                android:id="@+id/tvContent"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:ellipsize="end"                android:singleLine="true"                android:textColor="@color/text_gray"                android:textSize="@dimen/annotion_text" />        </LinearLayout>        <TextView            android:id="@+id/tvGroupTime2"            style="@style/user_comment_text"            android:layout_alignBottom="@id/tvGroupName2"            android:layout_alignParentRight="true"            android:singleLine="true" />        <TextView            android:id="@+id/tvGroupManger2"            android:layout_width="35dp"            android:layout_height="25dp"            android:layout_alignParentRight="true"            android:layout_below="@+id/tvGroupTime2"            android:layout_marginTop="2dp"            android:background="@drawable/selector_btn1"            android:gravity="center"            android:singleLine="true"            android:text="管理"            android:textColor="@color/text_white"            android:visibility="gone" />        <TextView            android:id="@+id/tvAddfriend"            android:layout_width="40dp"            android:layout_height="40dp"            android:layout_alignParentRight="true"            android:layout_below="@+id/tvGroupTime2"            android:background="@drawable/selector_btn1"            android:gravity="center"            android:singleLine="true"            android:text="添加"            android:textColor="@color/text_white"            android:visibility="gone" />    </RelativeLayout></LinearLayout>

主頁面listview的滾動監聽判斷是否需要替換標題:

 OnScrollListener onScroll = new OnScrollListener() {        @Override        public void onScrollStateChanged(AbsListView arg0, int arg1) {        }        @Override        public void onScroll(AbsListView view, int firstVisibleItem,                             int visibleItemCount, int totalItemCount) {            if (listUser.size() == 1) {                ((TitledListView) view).updateTitle(listUser.get(                        firstVisibleItem).getStrTitle());            }            if (listUser != null && listUser.size() > 1) {                // 第一項與第二項標題不同,說明標題需要移動                if (!TextUtils                        .equals(listUser                                .get(firstVisibleItem)                                .getStrTitle(), listUser.get(firstVisibleItem + 1)                                .getStrTitle())) {                    ((TitledListView) view).moveTitle(listUser.get(                            firstVisibleItem).getStrTitle());                } else {                    ((TitledListView) view).updateTitle(listUser.get(                            firstVisibleItem).getStrTitle());                }            }        }    };適配器判斷標題的顯示:

     vh.tvTitle.setText(grouper.getStrTitle());                if (position == 0) {                    vh.tvTitle.setVisibility(View.VISIBLE);                } else if (position < getCount()                        && !TextUtils.equals(listMember.get(position)                        .getStrTitle(), listMember.get(position - 1)                        .getStrTitle())) {                    vh.tvTitle.setVisibility(View.VISIBLE);                } else {                    vh.tvTitle.setVisibility(View.GONE);                }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国自产精品手机在线观看视频| 亚洲精品资源在线| 国产女人18毛片水18精品| 国产免费一区二区三区在线能观看| 美女福利精品视频| 国产欧美一区二区三区久久人妖| 久久天天躁狠狠躁夜夜av| 日韩中文在线观看| 中文精品99久久国产香蕉| 国产精品视频网址| 欧美黄色片免费观看| 欧美激情亚洲国产| 国产精品电影久久久久电影网| 欧美大片第1页| 亚洲第一区中文99精品| 国产精品毛片a∨一区二区三区|国| 日韩av一区二区在线| 97在线观看免费| 国产精品人成电影| 日韩在线播放一区| 97视频国产在线| 国产午夜精品全部视频播放| 97视频在线观看免费高清完整版在线观看| 69视频在线免费观看| 狠狠爱在线视频一区| 91精品视频在线| 欧美激情图片区| 色爱精品视频一区| 欧美日韩福利在线观看| 欧美午夜电影在线| 亚洲精品成人免费| 大胆欧美人体视频| 最新亚洲国产精品| 中文字幕无线精品亚洲乱码一区| 97欧美精品一区二区三区| 精品久久久久久久中文字幕| 国产免费观看久久黄| 91视频九色网站| 欧美黑人极品猛少妇色xxxxx| 91免费观看网站| 欧美日韩国内自拍| 精品成人乱色一区二区| 91国产精品视频在线| 国产亚洲视频中文字幕视频| 国产精品igao视频| 欧美日韩国产页| 久久久国产在线视频| 欧美激情性做爰免费视频| 国产欧美日韩亚洲精品| 粉嫩av一区二区三区免费野| 精品伊人久久97| 久久精品免费电影| 美女视频久久黄| 日韩在线播放av| 亚洲精选中文字幕| 97精品伊人久久久大香线蕉| 成人美女av在线直播| 最新91在线视频| 午夜精品www| 欧美国产第一页| 国产精品欧美日韩| 97色在线观看免费视频| 国产噜噜噜噜噜久久久久久久久| 欧美一级淫片aaaaaaa视频| 亚洲精品一区二区久| 欧美性猛交xxxx乱大交极品| 欧美日韩国产区| 一本色道久久综合狠狠躁篇怎么玩| 国产精品影院在线观看| 国产精品白嫩初高中害羞小美女| 国产中文字幕日韩| 欧美第一页在线| 日韩欧美高清视频| 欧美最猛黑人xxxx黑人猛叫黄| 日韩av手机在线看| 久久6免费高清热精品| 久久精品精品电影网| 国产在线高清精品| 欧美野外猛男的大粗鳮| 91精品国产综合久久香蕉最新版| 最近2019中文字幕mv免费看| 久久久久久国产精品三级玉女聊斋| 亚洲欧美一区二区精品久久久| 色伦专区97中文字幕| 欧美成人免费视频| 欧美日韩在线第一页| 91久久久国产精品| 国产日本欧美一区| 日韩av在线看| 国外成人在线播放| 亚洲电影免费观看高清完整版在线| 91久久国产综合久久91精品网站| 国产精品福利在线观看网址| 国产精品美乳一区二区免费| 久久精品国产精品亚洲| 欧美理论电影在线观看| 亚洲精品大尺度| 久久在线免费观看视频| 亚洲全黄一级网站| 久久精品青青大伊人av| 6080yy精品一区二区三区| 亚洲一区二区三区在线免费观看| 亚洲精品xxxx| 亚洲精品乱码久久久久久金桔影视| 亚洲男女自偷自拍图片另类| 亚洲成色999久久网站| 久久久av一区| 成人在线观看视频网站| 91热精品视频| 538国产精品视频一区二区| 亚洲自拍偷拍色图| 国产视频福利一区| 日本伊人精品一区二区三区介绍| 91国偷自产一区二区三区的观看方式| 亚洲乱亚洲乱妇无码| 日韩在线视频二区| 欧美在线视频一二三| 国产精品高潮在线| 国产日韩欧美视频在线| 亚洲成人黄色在线| 日韩中文字幕在线视频播放| 国产精品69av| 欧美www视频在线观看| 高清在线视频日韩欧美| 在线视频国产日韩| 欧美人在线视频| 自拍偷拍亚洲欧美| 久久影院免费观看| 97久久国产精品| 久久久久久国产精品| 中文字幕国内精品| 一个色综合导航| 国产一区二区黑人欧美xxxx| 国产一区私人高清影院| 在线观看日韩欧美| 国产精品国产三级国产aⅴ浪潮| 欧美精品激情在线观看| 午夜欧美不卡精品aaaaa| 国产精品欧美日韩一区二区| 免费99精品国产自在在线| 国产成人久久久| 亚洲精品在线视频| 亚洲免费av网址| 国产一区二区三区欧美| 欧美伦理91i| 久久91精品国产| 国产精品老牛影院在线观看| 欧美激情高清视频| 国产精品免费久久久久影院| 亚洲免费成人av电影| 国产在线精品一区免费香蕉| 欧美日韩美女在线观看| 亚洲天堂网站在线观看视频| 久久久久久国产精品三级玉女聊斋| 国产精品视频色| 国产精品无码专区在线观看| 久久色精品视频| 奇门遁甲1982国语版免费观看高清| 国产一区二区三区欧美| 97超级碰碰碰| 日韩国产欧美区| 久久久在线免费观看| 日韩大片在线观看视频| 午夜精品视频在线|