Android-custom multi-title bar Components

Source: Internet
Author: User
Tags call back

Android-custom multi-title bar Components

 

1. When our project has many subitem titles. slide the title left and right. click the title to switch to Fragment. the left arrow disappears when sliding to the leftmost, and the same occurs when sliding to the right. the right arrow disappears.

 

1) because we want to achieve the elasticity of sliding, we should rewrite the transverse sliding (onScrollChanged () Listener to control the display of the left and right sliding frames)

 

/*** @ Author Lean */public class extends HorizontalScrollView {private static final int MAX_X_OVERSCROLL_DISTANCE = 30; // maximum Y-axis moving size private Context mContext; private int mMaxYOverscrollDistance; private View mLeftIndicator; private View mRightIndicator; public BounceHorizontalScrollView (Context context, AttributeSet attrs) {super (context, attrs); mContext = context; initBounceVi Ew ();} public void setIndicator (View leftView, View rightView) {region = 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, primary, maxOverScrollY, isTouchEvent);} @ override void onScrollChanged (int l, int t, int oldl, int oldt) {super. onScrollChanged (l, t, oldl, oldt); if (m LeftIndicator! = 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. Because the arrow is to be displayed at the top of the interface, you need to override FrameLayout and set the arrow to the sliding interface.

 

After clicking the event, you need to call back the Click Event externally. Therefore, you need to deliver the Click Event task to the external business class.

 

/*** Health title ** @ author Lean @ date: 2014-8-28 */public class TitleFrameView extends FrameLayout implements OnClickListener {private View mLeftIndic; private View mRightIndic; private synchronized rollview; 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 (0 xFFAFBEAD); (TextView) findViewById (R. id. allpay_ TV )). setTextColor (0 xFFAFBEAD); (TextView) findViewById (R. id. unnurse_ TV )). setTextColor (0 xFFAFBEAD); (TextView) findViewById (R. id. nursing_ TV )). setTextColor (0 xFFAFBEAD); (TextView) findViewById (R. id. allnurse_ TV )). setTextColor (0 xFFAFBEAD); (TextView) v ). setTextColor (0 xFFFFFFFF);} public void initDefault () {findViewById (R. id. unpay_ TV ). extends mclick () ;}@ Overrideprotected 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);} @ Overridepublic 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 ;}}}


 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.