0

I need to make this kind of layout enter image description here

NB: sorry for the use of old ms paint

When I click button 2, page 1(the one with listview) will scale to 0 height (kind of an accordion), and page 2 will come up with translation. And now the problem is, after it looks like the image on the right, I cant click anything on it. After some check, all the click event goes through to page 1

Here is my code for the call:

public void openButtonTop(View v){
    if(!TopOpen){
        scaleViewY(ll, 0f, 1f,0f,false,how_long);
        translateView(
                buttonTanggal,0,0,
                -1*howfar,0,
                how_long);
        translateView(
                ll2,0,0,
                -1*howfar,0,
                how_long);
        TopOpen=true;
    }
}
public void openButtonBelow(View v){
    if(TopOpen){
        scaleViewY(ll, 1f, 0f,0f,true,how_long);
        translateView(
                buttonTanggal,0,0,
                0,-1*howfar,
                how_long);
        translateView(
                ll2,0,0,
                0,-1*howfar,
                how_long
        );
        TopOpen=false;
    }
}

And here is the animation function

public static void scaleViewY(final View v, float startScale, float endScale,float pivotY,final boolean gone,int how_long) {
    Animation anim = new ScaleAnimation(
            1f, 1f, // Start and end values for the X axis scaling
            startScale, endScale, // Start and end values for the Y axis scaling
            Animation.RELATIVE_TO_SELF, 0f, // Pivot point of X scaling
            Animation.RELATIVE_TO_SELF, pivotY); // Pivot point of Y scaling
    anim.setFillAfter(true); // Needed to keep the result of the animation
    anim.setDuration(how_long);
    anim.setAnimationListener(new Animation.AnimationListener() {
        @Override public void onAnimationStart(Animation animation) {
            //if(!gone)v.setVisibility(View.VISIBLE);
            //if(!gone)translateView(v,0,0,-410,0,0);
        }
        @Override public void onAnimationEnd(Animation animation) {
            //if(gone)v.setVisibility(View.GONE);
            //if(gone)translateView(v,0,0,0,-410,0);
        }
        @Override public void onAnimationRepeat(Animation animation) {}
    });
    v.startAnimation(anim);
}
public static void translateView(View v,float fromX,float toX,float fromY, float toY,int how_long){
    TranslateAnimation animation=new TranslateAnimation(fromX,toX,fromY,toY);
    animation.setFillAfter(true);
    animation.setDuration(how_long);
    v.startAnimation(animation);
}

One solution I found the best success with is set the visibilty to GONE for the page 1, but it makes a bit of blinking after page 2 slide up.

Does anyone know how to solve this?

EDIT: page2 is an included layout

aaron
  • 257
  • 6
  • 15
  • `TranslateAnimation` only animates where the view is drawn and does not update the view itself (e.g., position). You need to use `ObjectAnimator` to do this. You can learn more here https://developer.android.com/guide/topics/graphics/prop-animation.html#property-vs-view – GDA Feb 06 '18 at 03:24

2 Answers2

0

You need to make second page components clickable explicitly to handle click events as in

android:clickable ="true"
android:focusable = "true"
Rajan Kali
  • 12,627
  • 3
  • 25
  • 37
0

Checkout this answer https://stackoverflow.com/a/15662776/6732325

it's setting clickable attribute for 2nd fragment's layout to true

<RelativeLayout
  ...
  ...
  android:clickable="true" />
Kush Saini
  • 11
  • 1
  • 3
  • Then set clickable in the included layout, if changing included layout is not possible then, make a parent view for the included view and then set clickable attribute on that parent to true, like this:- – Kush Saini Jan 19 '18 at 05:15
  • The checkbox at page 1 is still got clicked. Any other guess? – aaron Jan 19 '18 at 06:55
  • Try adding background to the root view of fragment ' ' – Kush Saini Jan 19 '18 at 11:30
  • how does background color affect that? – aaron Jan 20 '18 at 01:15
  • It's not background colour it's setting background drawable of colour white to the view, so, maybe a background will not allow clicks to pass through the view – Kush Saini Jan 20 '18 at 02:39
  • Sorry for the late reply. But I've also put drawable color to both page (my own though). No effect – aaron Jan 22 '18 at 00:34