janishar / PlaceHolderView

This library provides advance views for lists and stacks. Some of the views are build on top of RecyclerView and others are written in their own. Annotations are compiled by annotation processor to generate bind classes. DOCS -->
http://janishar.com/PlaceHolderView
Apache License 2.0
2.11k stars 367 forks source link

SwipePlaceHolderView with only text hasn't fixed width #122

Open ondrejbudai opened 6 years ago

ondrejbudai commented 6 years ago

I need to use SwipePlaceHolderView to display cards consisting of only text. I would like the text to span over as much width as possible (90% of screen width). I tried the following method, but the card is acting weirdly: It's wider when I swipe the card to the left and is narrower when I swipe the card to the right. Consequently this makes the TextView to often change text wrap. Am I doing something wrong?

MainActivity.kt

swipe_view.getBuilder<SwipePlaceHolderView, SwipeViewBuilder<SwipePlaceHolderView>>()
    .setDisplayViewCount(3)
    .setSwipeDecor(SwipeDecor()
        .setPaddingTop(20))

card_layout.xml

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        card_view:cardCornerRadius="4dp"
        card_view:cardElevation="8dp"
        card_view:cardPreventCornerOverlap="false">

            <TextView
                android:id="@+id/meal_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="32dp"
                android:layout_marginBottom="32dp"
                android:layout_marginEnd="16dp"
                android:layout_marginStart="16dp"
                android:text="Bread with cheese and ham"
                android:textAlignment="center"
                android:textColor="#000"
                android:textSize="40sp" />
    </android.support.v7.widget.CardView>
</FrameLayout>
janishar commented 6 years ago

@ondrejbudai This might help https://medium.com/@janishar.ali/modifying-android-tinder-swipe-view-example-to-support-auto-resize-94f9c64f641e