daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

Main-layout change while in a sided-layout. #426

Open jmaire opened 7 years ago

jmaire commented 7 years ago

Hello, I have an issue when changing the text of a TextView in the main layout while my right-sided layout is visible. When I change the text, the right-sided layout is immediately hidden instead of remaining visible.

I've made this simple application to illustrate my problem. The number in the TextView is incremented every 3 seconds. So if you drag the right-sided layout, at the next incrementation, the layout will "refresh/reset" himself and i don't want that.

PS: When I set layout_width="match_parent" of the TextView, the problem doesn't happen.

Sources: MainActivity.java

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.item_layout);

        TextView countView = (TextView) findViewById(R.id.count);
        new Value(countView);

        SwipeLayout swipeLayout = (SwipeLayout) findViewById(R.id.swipe);
        LinearLayout rightLayout = (LinearLayout) findViewById(R.id.right);
        swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
        swipeLayout.addDrag(SwipeLayout.DragEdge.Right, rightLayout);
    }
}

Value.java

public class Value {
    private int value = 0;
    private final TextView view;

    private final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            value++;
            view.setText(value+"");
        }
    };

    public Value(TextView v) {
        view = v;
        incrementThread();
    }

    public void incrementThread() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true)
                    try {
                        handler.sendEmptyMessage(0);
                        Thread.sleep(2000);
                    } catch (InterruptedException ignored) {
                    }
            }
        }).start();
    }
}

item_layout.xml

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="100dp">

    <com.daimajia.swipe.SwipeLayout
        android:id="@+id/swipe"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/right"
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:background="@android:color/holo_blue_light"
            android:orientation="vertical">
        </LinearLayout>

        <LinearLayout
            android:id="@+id/main"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/holo_purple"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:id="@+id/count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="36sp" />
        </LinearLayout>

    </com.daimajia.swipe.SwipeLayout>

</android.support.v7.widget.CardView>