【问题标题】:Android ListView slide animation when item is selected选择项目时的Android ListView幻灯片动画
【发布时间】:2014-04-28 14:50:26
【问题描述】:

我有这个列表视图:

    @Override
        public void onComplete(List<Profile> friends) {

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mSpinner.setVisibility(View.GONE);
                    mSpinner.clearAnimation();
                }
                });

            // populate list
            List<String> values = new ArrayList<String>();
            for (Profile profile : friends) {
                //profile.getInstalled();
                values.add(profile.getName());
            }



            ArrayAdapter<String> friendsListAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.list_items2, values);
            friendsListAdapter.sort(new Comparator<String>() {
                @Override
                public int compare(String lhs, String rhs) {
                    return lhs.compareTo(rhs);    
                }
            });
            mFriendsList.setAdapter(friendsListAdapter);
        }
    };

在xml中:

<ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/imageView9"
    android:divider="#8A8A8A"
    android:cacheColorHint="#00000000"
    android:dividerHeight="0.9dp"
    android:listSelector="#ccc"
    android:choiceMode="singleChoice"
    android:layout_marginBottom="50dp"
    android:background="#fff"
    >

</ListView>

我已经尝试寻找这种或类似效果的解决方案,但我真的找不到任何有用的解决方案。

ListView 从 facebook 加载朋友,当在 ListView 中选择一个朋友时,它现在所做的是将所选项目更改为灰色,但我想要它做的是创建一个“滑动”动画,带颜色。像这样:

这是选择项目之前的 ListView:

当项目被选中时,颜色从右向左滑入:

完成后应该是这样的:

我怎样才能创造出这种效果?

【问题讨论】:

    标签: android android-listview


    【解决方案1】:

    你必须使用Android Animations。一种方法是创建用户选择的View 的位图并将其放在ListView 行的前面,然后从左到右开始用您想要的颜色绘制它。完成绘制后,更改行背景颜色并删除位图。

    要绘制单行,您必须在适配器中创建某种地图,并在适配器的 getView() 方法中跟踪您必须使用背景颜色绘制的 Views

    here 使用了类似的方法来重新排序 ListView

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-06
      • 2011-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-12
      • 1970-01-01
      相关资源
      最近更新 更多