项目挺大滑动ListView控件时, [英] Item getting bigger when sliding ListView

查看:103
本文介绍了项目挺大滑动ListView控件时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现在Android作为在Ultravisual iPhone应用程序显示一个列表的效果:

I would like to implement a list effect in android as the one displayed in the Ultravisual Iphone app :

同样的效果可以查看在Android上的米兰世博会2015年应用程序。

The similar effect can be view on the Expo Milano 2015 app in android.

我想往下滑ListView的时候顶部的项目变得越来越大。

I would like the top item get bigger when sliding down the ListView.

我不知道如何可以做到这一点......它是在当前视图上的第一个项目的动画?

I have no idea how this can be done... Is it an animation on the first item in the current view?

如果有人有一个例子或线索做到这一点,这将是伟大的!

If someone has an example or a clue to achieve this, it will be great!

感谢

推荐答案

嗯,我想达到这样的效果,它看起来是这样的:

Well I tried to achieve that effect and it looked like this:

首先,你需要开始定义的最大和最小的字体大小。我这样做:

First you need to start defining your max and min font size. I did this:

private final int MAX_FONTSIZE=50;
private final int MIN_FONTSIZE=12;

接下来,你需要保存你的屏幕总高度。在您的onCreate保存它是这样的:

Next you need to save your screen total height. On your onCreate save it like this:

    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    mScreenHeight = size.y;

然后重写你的列表视图onScroll事件做这样的事情:

Then override your listview onScroll event and do something like this:

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount) {
            if(listview.getChildCount()>0)
            for(int i=0;i<listview.getChildCount();i++)
            {
                float font = Math.min(Math.max(MAX_FONTSIZE - (float)(((MAX_FONTSIZE-MIN_FONTSIZE)/(mScreenHeight*0.3)))*Math.max(listview.getChildAt(i).getTop(),0),MIN_FONTSIZE),MAX_FONTSIZE);
                ((TextView)listview.getChildAt(i)).setTextSize(font);
            }
        }

0.3 意味着,在约30%的画面将永远是最小的字体大小。你可以调整为任何你想要的值。请记住, listview.getChildAt(我)将返回你吹你的适配器上的看法。就我而言,它只是一个简单的TextView,这就是为什么它是安全的,其转换为TextView的。您可能需要调用findViewById让你的TextView。

The 0.3 means that at about 30% of your screen it will always be the minimum font size. You can tweak that value for whatever you want. Remember that listview.getChildAt(i) will return the view that you inflate on your adapter. In my case it's just a simple textview, that's why it's safe to cast it to TextView. You might need to call findViewById to get your textview.

您可能还需要使TextView的中心,所以它看起来prettier。

You also might need to make the TextView centered so it looks prettier.

修改

由于运想改变视图的大小(它不应该与此code使用的)这里是一些黑客你可以做。首先改变你的最小/最大常量你想要什么(100安培,250)。然后,继续创建一个控制,如果列表视图中滚动与否的标志。在您的onScrollStateChanged加入这一行 isScrolling = I == SCROLL_STATE_TOUCH_SCROLL ||我== SCROLL_STATE_FLING; ,其中是onScrollStateChanged的第二个参数。下一步行更改为如果(listview.getChildCount()&GT; 0安培;&安培; isScrolling)。下一步骤是改变视图高度。要做到这一点,你必须改变它的LayoutParams。

Since op want to change the view's size (which should not be used with this code) here is some hack you can do. Start by changing your min/max constants to what you want (100 & 250). Then proceed to create a flag that controls if the listview is scrolling or not. On your onScrollStateChanged add this line isScrolling= i == SCROLL_STATE_TOUCH_SCROLL || i == SCROLL_STATE_FLING; where i is the second parameter of the onScrollStateChanged. Next change the line to if(listview.getChildCount()>0 && isScrolling). The next step is to change the view height. To do this you have to change it's layoutParams.

listview.getChildAt(我).setLayoutParams(新LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,Math.round(字体* getResources()getDisplayMetrics()密度)));

记住,这是,正如我所说的,一个简单的黑客。这不是,到目前为止,该最佳的解决方案。但由于它是一个复杂的事情,让我们坚持的基本知识。

Remember this is, like I said, a simple hack. This is not, by far, the best solution to this. But since it's a complex thing to do let's stick with the basics.

这篇关于项目挺大滑动ListView控件时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆