siyamed / android-shape-imageview

Custom shaped android imageview components
MIT License
2.67k stars 599 forks source link

ShapeImageView doesn't display image in Android 4.1 #57

Open Abhi347 opened 8 years ago

Abhi347 commented 8 years ago

I have tested ShapeImageView on 3 Android devices. One is Sony Xperia P running on Android 4.1, Another is Samsung Galaxy Note on 4.1.2 and the last one is LG Nexus 4 on 5.0

The ShapeDrawable doesn't work in the first 2 devices running on 4.1, while both these devices are working with RoundedImageView (Although the images appear in a square shape, not a rounded one). I want to have a Hexagonal shape, thus need ShapeDrawable. I have already tried HexagonImageView too. Note that the view is showing images in Lollipop version.

Here's my sample code -

    <com.github.siyamed.shapeimageview.ShapeImageView
        style="@style/AppAvatar"
        android:layout_gravity="center"
        android:background="#ff0"
        android:src="@drawable/male_19"/>

    <!-- In styles.xml-->
    <style name="AppAvatar" parent="">
        <item name="android:layout_width">80dp</item>
        <item name="android:layout_height">80dp</item>
        <item name="siShape">@raw/hexagon</item>
        <item name="siBorderWidth">4dp</item>
        <item name="siBorderColor">@color/primary</item>
    </style>

    <!-- In hexagon.svg -->
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    <svg version="1.1" xmlns="http://www.w3.org/2000/svg">
        <polygon
            points="723,314 543,625.769145 183,625.769145 3,314 183,2.230855 543,2.230855 723,314"
            fill="white"
            stroke="black"
            stroke-width="4"
            transform="rotate(30)"
              />
    </svg>

Am I missing something here?

lancewong2014 commented 7 years ago

I guess it caused by the method of onMeasure in this PorterImageView. Make square=false,and try again.

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        if(square) {
            int width = getMeasuredWidth();
            int height = getMeasuredHeight();
            int dimen = Math.min(width, height);
            setMeasuredDimension(dimen, dimen);
        }
    }
johncordeiro commented 7 years ago

I'm having the same problem here.

dohwaji commented 7 years ago
public ShaderImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setup(context, attrs, 0);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1
            && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        setLayerType(LAYER_TYPE_SOFTWARE, null);
    }
}
dingbuoyi commented 6 years ago

I have the same issue on Android version 16