Android Round-Arc ListView Implementation

Source: Internet
Author: User

This article takes you to realize the circular distribution of the ListView, the principle is very simple, that is, according to the ListView each item's height to offset each item.

First, customize a linearlayout, which is the root layout of each item in the ListView, which is used to offset each item.

The following code:

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" >//Incoming ListView height H = heigh    T        } @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 (widthmeas    Urespec, 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; }}

Below you can write your own demo test, is to write a ListView, and then use the above custom Matrixlinearlayout as the ListView item's root layout, self-clothed!

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.