3

In one of my projects I have implemented CustomTabHost from https://stackoverflow.com/a/19467434/3484668

What I am trying to do is semi-hide the tab host tab widget when clicked on a second child tab widget and then expand it if clicked again.

Here is the code of collapse :

frTabHost.getTabWidget().getChildTabViewAt(2).setOnClickListener(tabWidgetSecondChildListener);

Listener is :

    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;
        }
      }
    }

Code for 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);
        }
      }
    }

Problem is: It is collapsing the first time, then it is expanding the second time and everything is right. But then none of the clicks on fragment or image view is working. Please, could anyone help solve this?

Jitesh Mohite
  • 31,138
  • 12
  • 157
  • 147
Rushi M Thakker
  • 679
  • 2
  • 15
  • 34
  • Can you please include the code to show how you are attaching the clickListeners for both TabWidgetSecondChildListener and IvTabsListener? There seems to be nothing wrong with the code here. Your Toast Message should definitely pop up. So I am thinking the bug is somewhere else – Abhishek Nov 12 '17 at 15:38
  • @AbhishekSingh I don't get you. I have pretty clearly attached listeners in this code. Also I haven't made any toast message in this code. – Rushi M Thakker Nov 12 '17 at 17:50
  • Sorry I missed that because I didn't assume that you will be setting clicklisteners inside the OnClick... Will study in detail and answer – Abhishek Nov 13 '17 at 15:49
  • Can you also include the code where you are declaring the ivTabs? – Abhishek Nov 13 '17 at 15:55
  • Can you post a simple project with that behavior at github? – azizbekian Nov 15 '17 at 06:30
  • Sure will do by tomorrow @azizbekian – Rushi M Thakker Nov 15 '17 at 06:32

0 Answers0