如何动画全视图SearchView在操作栏中展开/折叠?

时间:2015-05-07 20:53:48

标签: android android-support-library searchview android-actionbar-compat

我正在使用rawValue库中的>> users = User.paginate(:all, :page => 1, :per_page => 10) => [] # query performed, verified correct: select * from (SELECT * FROM "USERS" WHERE ("USERS".is_deleted = 0 or "USERS".is_deleted is NULL) ORDER BY id) where rownum <= 10 >> users.size => 0 >> users.total_entries => 0 # regular pagination over the result works but is not optimal as it loads all records >> u2 = User.find(:all).paginate(:page => 1, :per_page => 10) => [#<User user_id: 4015857, ...> ... ] >> u2.size => 10 >> u2.total_entries => 32449 。我查看了this post,建议您只需设置SearchView

即可为搜索视图添加动画效果
support.v7

然而,上述内容对我不起作用。搜索视图似乎也仅填充横向As shown here中的部分屏幕宽度。我想要它fill_parent

我试图通过创建一个简单的动画解决这两个问题但在LayoutTransition失败,因为它似乎总是返回null。

最终目标是在操作栏中放置一个SearchView,它可以平滑地展开/折叠,并在横向上占据屏幕宽度的宽度。

有没有办法实现这个目标?

以下是我目前的搜索视图设置:

LinearLayout searchBar = (LinearLayout) searchView.findViewById(searchBarId);
//Give the Linearlayout a transition animation.
searchBar.setLayoutTransition(new LayoutTransition()); 

和menu_main.xml

searchView.getLayoutParams();

1 个答案:

答案 0 :(得分:0)

在oncreateoptions中做:

MenuItem searchitem = menu.findItem(R.id.search);
SearchView search= (SearchView) searchitem.getActionView();
ActionBar.LayoutParams p= new ActionBar.LayoutParams(ActionBar.LayoutParams.MATch_parent, same here)
search.setLayoutParams(p);
searchitem.expandActionView();