FlyingPumba / SimpleRatingBar

Open source project which features a simple yet powerful RatingBar alternative to Android's default
Apache License 2.0
1.03k stars 142 forks source link

onSizeChanged may oom #21

Open coolegos opened 7 years ago

coolegos commented 7 years ago

thank your great library.i use it in my app.i have a demo.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="becomeBig"
        android:text="Become Big"/>

    <View
        android:id="@+id/test_view"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_below="@id/button"
        android:background="#ffff0000"/>

    <com.iarcuschin.simpleratingbar.SimpleRatingBar
        android:id="@+id/bar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/test_view"
        android:layout_margin="8dp"
        android:paddingLeft="10dp"
        app:srb_numberOfStars="1"
        />
</RelativeLayout>

my app xml must be RelativeLayout, so my demo use RelativeLayout.When I click button the test_view will become MATCH_PARENT. SimpleRatingBar's onSizeChange height return a big number. it will oom when Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); i can't use LinearLayout/FrameLayout. so i do something in onSizeChange.

if (w > getResources().getDisplayMetrics().widthPixels || 
    h > getResources().getDisplayMetrics().heightPixels) {
            return;
        }

Can you give me some advice?

FlyingPumba commented 7 years ago

Hi, not sure if I can change the library so that it doesn't use the internalBitmap (although perhaps there is a way that I don't know). What numbers are you seeing as height ?

coolegos commented 7 years ago

h 16777168. image my phone is 720X1920, it may be different in other phone.

FlyingPumba commented 7 years ago

Well, that's big. I'll start thinking on how to solve it, but It might take me a while. If you find a workaround or fix please let me know.

FlyingPumba commented 7 years ago

Btw, have you tried using wrap_content for the height of the ratingbar ?

coolegos commented 7 years ago

i try wrap_content now, it will not invoke onSizeChange, so it will not oom. maybe something wrong with my layout.