在我的一个项目中,我已经从https://stackoverflow.com/a/19467434/3484668
实现了CustomTabHost我想要做的是在单击第二个子选项卡小部件时半隐藏选项卡主机选项卡小部件,然后再次单击时展开它。
以下是崩溃代码:
frTabHost.getTabWidget().getChildTabViewAt(2).setOnClickListener(tabWidgetSecondChildListener);
听众是:
private class TabWidgetSecondChildListener implements View.OnClickListener
{
@Override public void onClick(View view)
{
Log.d(TAG, "onClick: tabwidget clicked");
Toast.makeText(DashboardActivity.this, "onClick: tabwidget clicked", Toast.LENGTH_SHORT)
.show();
if (!isTabExpanded)
{
//Utility.semiExpand(frTabHost.getTabWidget(), frTabHost.getTabWidget().getHeight());
ObjectAnimator a = new ObjectAnimator();
a.setPropertyName("translationY");
a.setDuration((int) (2 * (frTabHost.getTabWidget().getHeight()
/ getResources().getDisplayMetrics().density)));
a.setTarget(frTabHost.getTabWidget());
a.setFloatValues(0, -frTabHost.getTabWidget().getHeight());
a.start();
ObjectAnimator b = new ObjectAnimator();
b.setPropertyName("translationY");
b.setDuration((int) (2 * ((ivTabs.getHeight() / 2)
/ getResources().getDisplayMetrics().density)));
b.setTarget(ivTabs);
b.setFloatValues(0, -ivTabs.getHeight() / 2);
b.start();
ivTabs.setClickable(false);
isTabExpanded = true;
} else
{
ObjectAnimator a = new ObjectAnimator();
a.setPropertyName("translationY");
a.setDuration((int) (2 * (frTabHost.getTabWidget().getHeight()
/ getResources().getDisplayMetrics().density)));
a.setTarget(frTabHost.getTabWidget());
a.setFloatValues(0, frTabHost.getTabWidget().getHeight());
a.start();
ObjectAnimator b = new ObjectAnimator();
b.setPropertyName("translationY");
b.setDuration((int) (2 * ((ivTabs.getHeight() / 2)
/ getResources().getDisplayMetrics().density)));
b.setTarget(ivTabs);
b.setFloatValues(0, ivTabs.getHeight() / 2);
b.start();
ivTabs.setClickable(true);
ivTabs.setOnClickListener(ivTabsListener);
isTabExpanded = false;
}
}
}
iVTabsLisener代码:
private class IvTabsListener implements View.OnClickListener
{
@Override public void onClick(View view)
{
Toast.makeText(DashboardActivity.this, "onClick: ivTabs clicked", Toast.LENGTH_SHORT).show();
if (!isTabExpanded)
{
ObjectAnimator a = new ObjectAnimator();
a.setPropertyName("translationY");
a.setDuration((int) (2 * (frTabHost.getTabWidget().getHeight()
/ getResources().getDisplayMetrics().density)));
a.setTarget(frTabHost.getTabWidget());
a.setFloatValues(0, -frTabHost.getTabWidget().getHeight());
a.start();
ObjectAnimator b = new ObjectAnimator();
b.setPropertyName("translationY");
b.setDuration(
(int) (2 * ((ivTabs.getHeight() / 2) / getResources().getDisplayMetrics().density)));
b.setTarget(ivTabs);
b.setFloatValues(0, -ivTabs.getHeight() / 2);
b.start();
isTabExpanded = true;
ivTabs.setClickable(true);
ivTabs.setOnClickListener(null);
}
}
}
问题是:它第一次崩溃,然后它第二次扩展,一切都是正确的。但是片段或图像视图上的所有点击都没有起作用。拜托,有人可以帮忙解决这个问题吗?