Android dashed line drawable potential ICS bug
Asked Answered
H

2

34

The following is a dashed line, defined as a ShapeDrawable in XML:

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">

    <size
        android:height="2dp"
        android:width="700dp" />

    <stroke
        android:width="1dp"
        android:color="@android:color/black"
        android:dashWidth="1dp"
        android:dashGap="2dp" />

</shape>

This will draw a nice dotted line on several Gingerbread phones. On the Galaxy Nexus however, the dashes appear to be ignored and the shape is drawn as a contiguous line. Even more curious, an emulator running ICS will render it correctly with the dashes, it's just the physical device screwing up.

Am I missing something obvious? Or is this really a bug with Android 4.0? The line is used in several places. Here is an example ImageView:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/observation_observe_side_margin"
    android:layout_marginRight="@dimen/observation_observe_side_margin"
    android:layout_marginTop="16dp"
    android:contentDescription="@string/dotted_line_description"
    android:src="@drawable/dotted_line" />
Herring answered 1/6, 2012 at 1:39 Comment(3)
I'm noticing the same issue on my app on the Galaxy Nexus. On my other devices 2.x devices it shows up as dotted.Autonomic
duplicate of https://mcmap.net/q/102310/-dotted-line-is-actually-not-dotted-when-app-is-running-on-real-android-deviceTonguelashing
possible duplicate of Dotted line is actually not dotted when app is running on real Android deviceTonguelashing
N
25

This issue is logged here http://code.google.com/p/android/issues/detail?id=29944 Turning off hardware acceleration will show the dashed line.

Naumachia answered 11/6, 2012 at 15:27 Comment(2)
Unfortunately this worsens my performance by about 500%. Any workarounds to prevent this?Astounding
Don't turn off hardware acceleration. CardView will lose it's shadow: #43407438.Expiable
I
51

The issue logged at http://code.google.com/p/android/issues/detail?id=29944 has a comment of applying the following to your view:

view.setLayerType(View.LAYER_TYPE_SOFTWARE, null)

This worked for me.

Infantry answered 28/11, 2012 at 16:50 Comment(4)
Note that if you don't want to edit the view programmatically you can also add the attribute android:layerType="software" to the XML definition.Dialecticism
API 11+ developer.android.com/reference/android/view/…Italianate
so in the example in the question. would you set android:layerType="software" to the ImageView or the shape?Panthia
I would do it on the ImageViewInfantry
N
25

This issue is logged here http://code.google.com/p/android/issues/detail?id=29944 Turning off hardware acceleration will show the dashed line.

Naumachia answered 11/6, 2012 at 15:27 Comment(2)
Unfortunately this worsens my performance by about 500%. Any workarounds to prevent this?Astounding
Don't turn off hardware acceleration. CardView will lose it's shadow: #43407438.Expiable

© 2022 - 2024 — McMap. All rights reserved.