Android Ê Ó ListView {μ Ö öíø {× Æ Â Û Ç çâ ¥ {§ ¹ û Û

Source: Internet
Author: User

Android Ê Ó ListView {μ Ö öíø {× Æ Â Û Ç çâ ¥ {§ ¹ û Û
Copyright § ~~~~â £°?


Ê μ Ï öô áí £° ¥ ¥² ¿À Ó órámáá ListView µäheadview À 'µ μ Ï ö£;;é» ° ónäë û à ¿ö öitem ¼ Ó Ã ± ³ ° µ μ Ö ö£ ¡

{× ********************************************************************** "Brush: java; "> package com. cyy. widget;/*** @ see http://blog.csdn.net/chenlove1 * @ author chenyingyou **/public class NestHelper {public static final int BACK_COLOR = 0xFFF8F3D5; // ± ³ ¾ ° É «public static final int LINE_COLOR = 0xFF5A595A; // Ï Ñ n'õ É «public static final int LINE_WIDTH = 2; // optional parameter maid public static final int LINE_SPAN = 4; // optional parameter maid}

à ¿¸ öitem µä± ³ ° µ µö ö× î Î ª ° £ ä£ç Ç '''' Â Ë £ £°

package com.cyy.widget;import android.content.Context;import android.graphics.Canvas;import android.graphics.ColorFilter;import android.graphics.Paint;import android.graphics.drawable.Drawable;import android.util.AttributeSet;import android.widget.FrameLayout;/** * @see http://blog.csdn.net/chenlove1 * @author chenyingyou *  */public class NestItemLayout extends FrameLayout implements NestNotifyData {public NestItemLayout(Context context) {super(context);}public NestItemLayout(Context context, AttributeSet attrs) {super(context, attrs);}public NestItemLayout(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);}@SuppressWarnings("deprecation")@Overridepublic void notifyDataSetChanged(int count, int position) {setBackgroundDrawable(new NestDrawable(count, position));}/** »æÖÆitem Layout±³¾° Á½±ß¸úµ×²¿ */class NestDrawable extends Drawable {private int linsCount = 0;// Á½±ß¸÷ÓжàÉÙÌõÏßprivate int span = 0;// Ò»ÌõÏߵĿí¶È£¨Ïß¼ÓÏßÖ¼ä¾à£public NestDrawable(int count, int position) {linsCount = count - position;if (linsCount > 5) {linsCount = 5;// Ò»±ß×î¶à5Ìõ}span = (NestHelper.LINE_WIDTH + NestHelper.LINE_SPAN);setPadding(span * linsCount, 0, span * linsCount,NestHelper.LINE_WIDTH);}@Overridepublic void draw(Canvas canvas) {canvas.drawColor(NestHelper.BACK_COLOR);Paint paint = new Paint();paint.setColor(NestHelper.LINE_COLOR);paint.setStrokeWidth(NestHelper.LINE_WIDTH);// »æÖƵײ¿Ïßcanvas.drawLine(span * (linsCount - 1), getHeight()- NestHelper.LINE_WIDTH / 2, getWidth() - span* (linsCount - 1), getHeight() - NestHelper.LINE_WIDTH / 2,paint);for (int i = 0; i < linsCount; i++) {// »æÖÆ×ó±ßÏßcanvas.drawLine(span * i + NestHelper.LINE_WIDTH / 2, 0, span* i + NestHelper.LINE_WIDTH / 2, getHeight(), paint);// »æÖÆÓÒ±ßÏßcanvas.drawLine(getWidth() - span * i - NestHelper.LINE_WIDTH/ 2, 0, getWidth() - span * i - NestHelper.LINE_WIDTH/ 2, getHeight(), paint);;}}@Overridepublic void setAlpha(int alpha) {}@Overridepublic void setColorFilter(ColorFilter cf) {}@Overridepublic int getOpacity() {return 0;}}}

?

package com.cyy.widget;import android.annotation.SuppressLint;import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.util.AttributeSet;import android.view.View;import android.widget.AbsListView;import android.widget.AbsListView.LayoutParams;/** * @see http://blog.csdn.net/chenlove1 * @author chenyingyou *  */public class NestHeadView extends View implements NestNotifyData {private int linsCount = 0;// ×´¿öÒª»æÖƶàÉÙÌõÏßprivate int span = 0;// Ò»ÌõÏߵĿí¶È£¨Ïß¼ÓÏßÖ¼ä¾à£public NestHeadView(Context context) {super(context);}public NestHeadView(Context context, AttributeSet attrs) {super(context, attrs);}public NestHeadView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);}@SuppressLint("DrawAllocation")@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);canvas.drawColor(NestHelper.BACK_COLOR);Paint paint = new Paint();paint.setColor(NestHelper.LINE_COLOR);paint.setStrokeWidth(NestHelper.LINE_WIDTH);for (int i = 0; i < linsCount; i++) {// »æÖÆ×ó±ßÏßcanvas.drawLine(span * i + NestHelper.LINE_WIDTH / 2, span * i,span * i + NestHelper.LINE_WIDTH / 2, getHeight(), paint);// »æÖÆÓÒ±ßÏßcanvas.drawLine(getWidth() - span * i - NestHelper.LINE_WIDTH / 2,span * i,getWidth() - span * i - NestHelper.LINE_WIDTH / 2,getHeight(), paint);// »æÖƵײ¿Ïßcanvas.drawLine(span * (linsCount - 1 - i), getHeight() - span * i- NestHelper.LINE_WIDTH / 2, getWidth() - span* (linsCount - 1 - i), getHeight() - span * i- NestHelper.LINE_WIDTH / 2, paint);}}@Overridepublic void notifyDataSetChanged(int count, int position) {linsCount = count - position;if (linsCount > 5) {linsCount = 5;// Ò»±ß×î¶à5Ìõ}span = (NestHelper.LINE_WIDTH + NestHelper.LINE_SPAN);setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,span * (linsCount - 1) + NestHelper.LINE_WIDTH));invalidate();}}
* Comment ° óöø comment 'listview:

package com.cyy.widget;import android.content.Context;import android.util.AttributeSet;import android.widget.ListView;/** * @see http://blog.csdn.net/chenlove1 * @author chenyingyou *  */public class NestListView extends ListView implements NestNotifyData {private NestHeadView headView;public NestListView(Context context) {super(context);initView();}public NestListView(Context context, AttributeSet attrs) {super(context, attrs);initView();}public NestListView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);initView();}private void initView() {headView = new NestHeadView(getContext());addHeaderView(headView);}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);super.onMeasure(widthMeasureSpec, expandSpec);}@Overridepublic void notifyDataSetChanged(int count, int position) {headView.notifyDataSetChanged(count, position);}public NestNotifyData getNotifyData() {return this;}}



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.