多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 互聯網 > Android-自定義多標題欄組件

Android-自定義多標題欄組件

來源:程序員人生   發布時間:2014-10-11 08:00:01 閱讀次數:2497次


1如圖,當我們的項目有很多子項標題的時候.需要對標題實現左右滑動.點擊標題切換Fragment.當滑動最左邊的時候左箭頭消失,滑至右邊的時候同理.右箭頭消失.


1)因為我們要對滑動實現彈力效果.故應該重寫橫向滑動(onScrollChanged()監聽器用于對左右滑動框顯示控制)

/** * @author Lean */ public class BounceHorizontalScrollView extends HorizontalScrollView { private static final int MAX_X_OVERSCROLL_DISTANCE = 30;// 最大Y軸移動尺寸 private Context mContext; private int mMaxYOverscrollDistance; private View mLeftIndicator; private View mRightIndicator; public BounceHorizontalScrollView(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; initBounceView(); } public void setIndicator(View leftView,View rightView){ mLeftIndicator=leftView; mRightIndicator=rightView; } private void initBounceView() { final DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); final float density = metrics.density; mMaxYOverscrollDistance = (int) (density * MAX_X_OVERSCROLL_DISTANCE); } @Override @SuppressLint("NewApi") protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { return super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, mMaxYOverscrollDistance,maxOverScrollY, isTouchEvent); } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); if (mLeftIndicator!=null&&mRightIndicator!=null) { if (l<=0) { mLeftIndicator.setVisibility(View.GONE); mRightIndicator.setVisibility(View.VISIBLE); }if (l==180) { mLeftIndicator.setVisibility(View.VISIBLE); mRightIndicator.setVisibility(View.GONE); }else if(l<180&&l>0) { mLeftIndicator.setVisibility(View.VISIBLE); mRightIndicator.setVisibility(View.VISIBLE); } } } }

2.因為箭頭要呈現在界面最上,因此需要重寫FrameLayout.并把箭頭設置進滑動界面.

因為點擊后需要對外回調點擊事件,因此需要把點擊事件的任務交付給外面的業務類.

/** * 健康標題 * * @author Lean @date:2014-8-28 */ public class TitleFrameView extends FrameLayout implements OnClickListener{ private View mLeftIndic; private View mRightIndic; private BounceHorizontalScrollView mScrollView; public TitleFrameView(Context context, AttributeSet attrs) { super(context, attrs); } public void setItemClickListener(OnClickListener itemClickListener) { findViewById(R.id.unpay_tv).setOnClickListener(itemClickListener); findViewById(R.id.allpay_tv).setOnClickListener(itemClickListener); findViewById(R.id.unnurse_tv).setOnClickListener(itemClickListener); findViewById(R.id.nursing_tv).setOnClickListener(itemClickListener); findViewById(R.id.allnurse_tv).setOnClickListener(itemClickListener); } public void reShowItemTvColor(View v) { ((TextView)findViewById(R.id.unpay_tv)).setTextColor(0xFFAFBEAD); ((TextView)findViewById(R.id.allpay_tv)).setTextColor(0xFFAFBEAD); ((TextView)findViewById(R.id.unnurse_tv)).setTextColor(0xFFAFBEAD); ((TextView)findViewById(R.id.nursing_tv)).setTextColor(0xFFAFBEAD); ((TextView)findViewById(R.id.allnurse_tv)).setTextColor(0xFFAFBEAD); ((TextView)v).setTextColor(0xFFFFFFFF); } public void initDefault() { findViewById(R.id.unpay_tv).performClick(); } @Override protected void onFinishInflate() { super.onFinishInflate(); mLeftIndic=findViewById(R.id.iv_left); mLeftIndic.setOnClickListener(this); mRightIndic=findViewById(R.id.iv_right); mRightIndic.setOnClickListener(this); mScrollView=(BounceHorizontalScrollView) findViewById(R.id.scroll); mScrollView.setIndicator(mLeftIndic, mRightIndic); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.iv_left: mScrollView.scrollBy(-180,0); break; case R.id.iv_right: mScrollView.scrollBy(180,0); break; default: break; } } }

其代碼的XML如下:

<?xml version="1.0" encoding="utf-8"?> <com.csz.vc.zbhealth.widget.TitleFrameView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#1F9401" > <com.csz.vc.zbhealth.widget.BounceHorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/scroll" android:scrollbars="none" > <LinearLayout android:layout_height="40dip" android:layout_width="match_parent" android:orientation="horizontal" > <TextView android:id="@+id/unpay_tv" android:layout_height="match_parent" android:layout_width="90dip" android:text="@string/unpay" android:textSize="18sp" android:gravity="center" android:textColor="@color/white" android:background="#1F9401" /> <TextView android:id="@+id/allpay_tv" android:layout_height="match_parent" android:layout_width="90dip" android:text="@string/allpay" android:textSize="18sp" android:gravity="center" android:textColor="@color/white" android:background="#1F9401" /> <TextView android:id="@+id/unnurse_tv" android:layout_height="match_parent" android:layout_width="90dip" android:text="@string/unnurse" android:textSize="18sp" android:gravity="center" android:textColor="@color/white" android:background="#1F9401" /> <TextView android:id="@+id/nursing_tv" android:layout_height="match_parent" android:layout_width="90dip" android:text="@string/nursing" android:textSize="18sp" android:gravity="center" android:textColor="@color/white" android:background="#1F9401" /> <TextView android:id="@+id/allnurse_tv" android:layout_height="match_parent" android:layout_width="90dip" android:text="@string/allnurse" android:textSize="18sp" android:gravity="center" android:textColor="@color/white" android:background="#1F9401" /> </LinearLayout> </com.csz.vc.zbhealth.widget.BounceHorizontalScrollView> <ImageView android:id="@+id/iv_left" android:layout_height="match_parent" android:layout_width="30dip" android:layout_gravity="center_vertical|left" android:scaleType="center" android:src="@drawable/arrow_left" /> <ImageView android:id="@+id/iv_right" android:layout_height="match_parent" android:layout_width="30dip" android:layout_gravity="center_vertical|right" android:scaleType="center" android:src="@drawable/arrow_right" /> </com.csz.vc.zbhealth.widget.TitleFrameView>

















生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 欧美日韩大片 | 老子午夜我不卡在线理伦 | 一区二区不卡久久精品 | 在线观看三级视频 | 高清国产精品久久 | 亚洲一级片免费 | 欧美另类性视频在线看 | 波多野结衣中文字幕久久 | 欧美aa在线观看 | 亚洲综合精品成人啪啪 | 欧美一区二区三区男人的天堂 | 亚洲欧美视频在线播放 | 黄站在线观看 | 中文字幕中文字幕中中文 | 伊人情人综合网 | 亚洲视频 欧美视频 | 亚洲午夜久久久久国产 | 国产视频一区二 | 手机看片福利在线 | 久久99亚洲精品一区二区 | 国产mv在线观看 | 最新欧美精品一区二区三区不卡 | 国产成在线观看免费视频成本人 | 欧美性受xxxx白人性爽网站 | xxxx大片| 亚洲午夜久久久久国产 | 亚洲 图片 小说 欧美 另类 | 亚拍精品一区二区三区 | 国产福利不卡一区二区三区 | 欧美jizz18性欧美 | 国产成人久久精品激情91 | 中文字幕第二区 | 精品福利一区二区免费视频 | 中文字幕亚洲欧美日韩不卡 | 成人a视频在线观看 | 久久亚洲精中文字幕冲田杏梨 | 天天色成人网 | 女人色图 | 亚洲精品福利在线观看 | 欧美性猛交xxxx黑人喷水 | 日韩欧美中文字幕一区 |