編輯:關於Android編程
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); } } } }
因為點擊後需要對外回調點擊事件,因此需要把點擊事件的任務交付給外面的業務類.
/** * 健康標題 * * @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; } } }
最近做一個效果:在手機設置裡面“關於手機”裡面添加一項來顯示當前手機cpu使用率的曲線!其實現效果如下圖所示: 上圖關於手機的第一項就是我要實現的效果!今天來講講這個曲
本篇博客內容轉自 github: https://github.com/shwenzhang/AndResGuard/blob/master/README.zh-cn.m
EditView類繼承自TextView類,EditView與TextView最大的不同就是用戶可以對EditView控件進行編輯,
特點:改變的是對象的實際屬性 不僅可以應用於View, 有getter和setter方法的都可以在xml中定義放在res\animator中如:animator_alph