当我向上滚动ListView并在向下滚动时再次显示时,我试图隐藏TabHost,但我不知道为什么当我向上滚动时,只有tabhost的最后一项是隐藏和再次显示,这就是我如何做到这一点,我称之为" HideTab"在我的FragmentLitos中。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mTabHost = new FragmentTabHost(getActivity());
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.tabFrameLayout);
mTabHost.getTabWidget().setDividerDrawable(null);
mTabHost.addTab(
mTabHost.newTabSpec("home").setIndicator(getTabIndicator(mTabHost.getContext(), R.string.inst, R.drawable.home)),
FragmentLitos.class, null);
mTabHost.addTab(
mTabHost.newTabSpec("prop").setIndicator(getTabIndicator(mTabHost.getContext(), R.string.prop, R.drawable.proposito)),
FragmentPropositos.class, null);
mTabHost.addTab(
mTabHost.newTabSpec("fav").setIndicator(getTabIndicator(mTabHost.getContext(), R.string.fav, R.drawable.heart)),
FavFragment.class, null);
mTabHost.addTab(
mTabHost.newTabSpec("chat").setIndicator(getTabIndicator(mTabHost.getContext(), R.string.msg, R.drawable.chat)),
MsgFragment.class, null);
mTabHost.addTab(
mTabHost.newTabSpec("user").setIndicator(getTabIndicator(mTabHost.getContext(), R.string.perfil, R.drawable.user)),
FragmentTab.class, null);
mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
if(tabId.equals("user")){
NavigationMain.Perfil();
}
}
});
return mTabHost;
}
private View getTabIndicator(Context context, int title, int icon) {
v = LayoutInflater.from(context).inflate(R.layout.tab_layout, null);
ImageView iv = (ImageView) v.findViewById(R.id.imageView);
ln = (LinearLayout) v.findViewById(R.id.layout_tab);
iv.setImageResource(icon);
TextView tv = (TextView) v.findViewById(R.id.textView);
tv.setText(title);
return v;
}
public void HideTab(final JazzyListView list){
list.setOnScrollListener(new AbsListView.OnScrollListener() {
int mLastFirstVisibleItem = 0;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (view.getId() == list.getId()) {
final int currentFirstVisibleItem = list.getFirstVisiblePosition();
if (currentFirstVisibleItem > mLastFirstVisibleItem) {
v.animate().translationY(-v.getBottom()).setInterpolator(new AccelerateInterpolator()).start();
} else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
v.animate().translationY(0).setInterpolator(new DecelerateInterpolator()).start();
}
mLastFirstVisibleItem = currentFirstVisibleItem;
}
}
});
}