jmartinesp / SpannedGridLayoutManager

Android RecyclerView.LayoutManager that resizes and reorders views based on SpanSize
MIT License
600 stars 105 forks source link

Element size little too big ? #11

Closed jaumard closed 7 years ago

jaumard commented 7 years ago

I have this layout:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:bind="http://schemas.android.com/apk/res-auto"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools">

    <data>

        <import type="android.view.View"/>

        <variable
            name="data"
            type="com.mylisabox.network.devices.models.Device"/>

        <variable
            name="builder"
            type="com.mylisabox.lisa.common.TemplateMobileViewBuilder"/>

        <variable
            name="populator"
            type="com.mylisabox.common.device.TemplateViewPopulator"/>

        <variable
            name="widgetHandler"
            type="com.mylisabox.common.device.WidgetHandler"/>
    </data>

    <android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        card_view:cardCornerRadius="4dp"
        card_view:cardElevation="@dimen/cardview_default_elevation">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/widgetHeader"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/widgetTitle"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:ellipsize="end"
                    android:lines="1"
                    android:maxLines="1"
                    android:padding="@dimen/space_normal"
                    android:text="@{data.name}"
                    android:textAppearance="?android:textAppearanceLarge"
                    android:textStyle="bold"
                    tools:text="My widget"/>

                <com.mylisabox.common.ui.ToggleImageButton
                    android:id="@+id/widgetFavorite"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@null"
                    android:padding="@dimen/space_small"
                    android:checked="@{data.favorite}"
                    android:src="@drawable/ic_favorite_24dp"
                    android:tint="@drawable/ic_color_selector"/>
            </LinearLayout>

            <View
                style="@style/Divider"/>

            <LinearLayout
                android:id="@+id/widgetContent"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:orientation="vertical"
                bind:builder="@{builder}"
                bind:device="@{data}"
                bind:widgetHandler="@{widgetHandler}"
                bind:populator="@{populator}"/>
        </LinearLayout>
    </android.support.v7.widget.CardView>
</layout>

And it look like this in the preview:

capture d ecran 2017-11-05 a 20 12 04

But once on the emulator I get this: device-2017-11-05-201349

Can't manage to find why my content is trunked as I don't have any fixed sizes. So maybe there a problem with the size of the element itself ?

jmartinesp commented 7 years ago

Could you upload a sample somewhere so I can have all the involved dimens and styles? Thanks.

jaumard commented 7 years ago

Sure I'll try to upload a sample asap :)

jaumard commented 7 years ago

Ok I just made a test you can reproduce easily by modifying your GridItemViewon your sample app and set on init:

    title.gravity = Gravity.RIGHT or Gravity.CENTER_VERTICAL
    addView(title, FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT))

You'll see the number disappear

jaumard commented 7 years ago

I also put span to 2 and here is what it look like:

device-2017-11-07-222712

jmartinesp commented 7 years ago

It seems like I did count decoration insets to layout the items, but not to measure their contents. I'm testing a new commit and uploading soon if everything is fine.

jmartinesp commented 7 years ago

Should be fixed in version 2.0.1.

jaumard commented 7 years ago

Thanks a lot :)

jaumard commented 7 years ago

All good now @Arasthel ! :D device-2017-11-08-072006