LayoutParams Issue Java

  Kiến thức lập trình

I have this for animating a RIGHT swipe and it works great:

good swipe

if(direction == RIGHT){
    if(distance < 217) {

        layoutParams.leftMargin = (int) distance + startLeftMargin;
        layoutParams.topMargin = startTopMargin;
        call.setVisibility(View.VISIBLE);
        straddle.setVisibility(View.GONE);
        bet.setVisibility(View.GONE);
        fold.setVisibility(View.GONE);
        ViewGroup.LayoutParams layoutParams = call.getLayoutParams();

        layoutParams.width = (int) getResources().getDisplayMetrics().density * ((int) distance);

            call.setLayoutParams(layoutParams);


    }
<TextView
    android:id="@+id/call"
    android:layout_width="1dp"
    android:layout_height="96dp"
    android:layout_marginStart="68dp"
    android:layout_marginTop="50dp"
    android:background="@drawable/call"
    android:gravity="center|start"
    android:paddingStart="@dimen/default_gap"
    android:text="Call"
    android:textColor="@color/white"
    android:textSize="25sp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"

    />

I have this for animating a LEFT swipe, but it is not working well. As the button moves to the left, the black animation with the word Str. goes to the right. I’d like the black background to stay stationary while the button moves.

bad swipe

} else if(direction == LEFT){
    if(distance < 217) {
        layoutParams.leftMargin = (int) (-distance) + startLeftMargin;
        layoutParams.topMargin = startTopMargin;
        call.setVisibility(View.GONE);
        straddle.setVisibility(View.VISIBLE);
        bet.setVisibility(View.GONE);
        fold.setVisibility(View.GONE);

        ViewGroup.LayoutParams layoutParams = straddle.getLayoutParams();
        layoutParams.width = (int) getResources().getDisplayMetrics().density * (int) distance;

        straddle.setLayoutParams(layoutParams);

    }
<TextView
    android:id="@+id/straddle"
    android:layout_width="1dp"
    android:layout_height="96dp"
    android:layout_marginStart="68dp"
    android:layout_marginTop="50dp"
    android:background="@drawable/straddle"
    android:gravity="center|end"
    android:paddingEnd="@dimen/default_gap"
    android:text="Str."
    android:textColor="@color/white"
    android:textSize="25sp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    />

I really can’t figure out what the issue might be, if anyone has any ideas i’d really apreciate it.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT