使用SupportActionbar隐藏选项卡的动画

时间:2014-01-04 12:00:28

标签: java android animation android-actionbar android-tabhost

我已根据指示in the android documentation.

在我的应用中实现了导航抽屉

一切正常,但由于我的一些片段正在使用标签,我希望在抽屉展开时同时“滚动”tabviews。如图所示:Like illustrated here. 我的actionBarToggle中的onDrawerSlide()方法非常适合它,因为它传递了抽屉展开的距离百分比。

我在actionBarToggle的{​​{1}}和onDrawerOpened()方法中更改了操作栏的导航模式,一切正常。但我想要一些动画,因为它现在看起来非常粗糙。 [抽屉打开 - 粉扑标签已消失 puff ;抽屉关闭 - 粉扑标签再次出现 puff ]

我目前的代码。

onDrawerClosed()

我希望获得tabhost / view或其他内容,并根据 drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.navigation, R.string.closed) { public void onDrawerClosed(View view) { supportInvalidateOptionsMenu(); } public void onDrawerOpened(View drawerView) { setTitle(getString(R.string.navigation)); setIcon(R.drawable.abc_ic_search_api_holo_light); supportInvalidateOptionsMenu(); } @Override public void onDrawerSlide(View drawerView, float slideOffset) { // TODO animation super.onDrawerSlide(drawerView, slideOffset); } }; 设置它的高度。

slideOffset

如何获得 @Override public void onDrawerSlide(View drawerView, float slideOffset) { TabView tabView = actionBar.getTabView(); // how do I get the view where the tabs are shown? ViewGroup.LayoutParams tabViewLayoutParams = tabView.getLayoutParams(); ViewGroup.LayoutParams tabViewNewLayoutParams = new ViewGroup.LayoutParams(a.width, (int)((1 - slideOffset) * normalTabHeight)) drawer.setLayoutParams(tabViewNewLayoutParams ); super.onDrawerSlide(drawerView, slideOffset); } 所在的view

How can I get the view where the tabs are in?

我正在使用tabs的支持库,因此使用API 7+

操作栏中如何调用“SupportActionBar”?是否有可能获得此“tabhost”并以编程方式在运行时更改它的高度?

1 个答案:

答案 0 :(得分:1)

问题是操作栏选项卡容器会自己进行高度测量,因此为其LayoutParams指定自定义高度对其布局没有影响。 一个公共方法来改变它的高度,但容器类本身不会被框架公开。

在不使用反射的情况下更改高度的唯一方法是更改​​支持库,即使在后蜂窝设备中也可以使用它自己的实现,而不是委托给框架,并可能在选项卡容器中添加一个方法来隐藏滚动动画类似于导航抽屉。或者您可以使用自己的选项卡实现,可能会从操作栏中复制代码。

如果您不需要回收布局中的标签空间,另一种可能是使用淡入淡出动画。

相关问题