Create a dropdown List in android not spinner

2019-07-21 09:11发布

In my application I want to create a dropDown that shows data, but the dropDown looks like a dropDown as shown in web not like a spinner.

标签: android
2条回答
在下西门庆
2楼-- · 2019-07-21 09:24

You can create an animation class like this

public class DropDownAnimation extends Animation {
    public int height, width;

    @Override
    public void initialize(int width, int height, int parentWidth,
            int parentHeight) {
        // TODO Auto-generated method stub
        super.initialize(width, height, parentWidth, parentHeight);
        this.width = width;
        this.height = height;
        setDuration(500);
        setFillAfter(true);
        setInterpolator(new LinearInterpolator());
    }

    Camera camera = new Camera();

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        // TODO Auto-generated method stub
        super.applyTransformation(interpolatedTime, t);

        Matrix matrix = t.getMatrix();
        camera.save();

        camera.getMatrix(matrix);
        matrix.setTranslate(0, (height * interpolatedTime));

        matrix.preTranslate(0, -height);
        camera.restore();

        this.setAnimationListener(this);
    }

and use it like this :

    LinearLayout ll = (LinearLayout) findViewById(R.id.parentLayout);
    ll.startAnimation(new DropDownAnimation());
查看更多
欢心
3楼-- · 2019-07-21 09:32

I have created a dropdown demo project on github to help out with this I'm my mind missing view/widget.

Its based on a text view (title) used to display the currently selected alternative, and a linear layout containing the alternative. When the title is clicked i animate in the linear layout with the alternatives, and once a alt is selected the linear layout is animated out.

The project can be found here:

https://github.com/erbsman/DropDownDemo

hope this helps :)

查看更多
登录 后发表回答