Android arc ListView implementation, androidlistview

Source: Internet
Author: User

Android arc ListView implementation, androidlistview

This article will show you how to arrange the Arc Distribution of ListView. The principle is very simple, that is, to offset each Item based on the height of each item in ListView.

First, define a LinearLayout. This is the root layout of each Item in ListView, which is used to offset each item.

The code below:

Public class MatrixLinearLayout extends LinearLayout {private int h = 0; private float fullTrans = 40f; public MatrixView (Context context, AttributeSet attrs) {super (context, attrs );} public void setParentHeight (int height) {<pre name = "code" class = "java"> // input the height of ListView h = height ;} @ Override protected void dispatchDraw (Canvas canvas) {canvas. save (); int top = getTop (); float trans = calculatetrans (top, h); Matrix m = canvas. getMatrix (); m. preTranslate (-2/getWidth (),-2/getHeight (); m. postTranslate (trans, 0); canvas. concat (m); super. dispatchDraw (canvas); canvas. restore () ;}@ Override protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {super. onMeasure (widthMeasureSpec, heightMeasureSpec);} private float calculatetrans (int top, int h) {float result = 0f; if (top <= h/2.349f) {result = (h/2f-top)/(h/7f) * fullTrans;} else if (top> h/2.349f) {result = (top-h/3f) /(h/7f) * fullTrans;} return result ;}}

Next, you can write a demo and test it by yourself. You can write a ListView and use the custom MatrixLinearLayout above as the root layout of the ListView item! 



How does android listview achieve this rounded corner and press effect? The question is sent again. Come and get the score.

It can be done by layout and a little logic. Specifically, the list body actually has a Margin value left and right, while the above transparent cover layer is full between the left and right, which makes it easy.

You can see the demo of my attachment. I have not adjusted the color. I am not very good at Color adjustment. But the effect is similar.


How does android use CheckBox + ListView to obtain the values of multiple controls on the selected items!

The score is too low !!!

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.