10

When I am using android dotted line its working fine in Small screens, but not working in Samsung S3 device and higher versions.

Screenshots

samsung Device

And

Small screens

drawable/dashline.xml

<?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="line" >

     <stroke
        android:dashWidth="20sp"
        android:dashGap="20sp"
        android:width="2dp"
         android:color="#FF0000" />

     </shape>

XML

 <ImageView
    android:id="@+id/button1"
    android:layout_width="fill_parent"
    android:layout_height="6dp"
    android:background="@drawable/dash_line" />   

If someone can help me out in this, any idea is appreciable.

VenomVendor
  • 15,064
  • 13
  • 65
  • 96
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
  • duplicate of http://stackoverflow.com/a/26296229/185022 – AZ_ Oct 10 '14 at 09:45
  • possible duplicate of [Dotted line is actually not dotted when app is running on real Android device](http://stackoverflow.com/questions/18931679/dotted-line-is-actually-not-dotted-when-app-is-running-on-real-android-device) – AZ_ Oct 10 '14 at 09:45

5 Answers5

28

set android:layerType="software" for your imageView. Check the docs for android:layerType.

PrincessLeiha
  • 3,144
  • 4
  • 32
  • 53
2

Try changing sp to dp to:

<stroke
    android:dashWidth="20dp"
    android:dashGap="20dp"
    android:width="2dp"
    android:color="#FF0000" />
waqaslam
  • 67,549
  • 16
  • 165
  • 178
1

Stroke WIDTH must be smaller than the size HEIGHT.

(Stroke width is the width of the line. Size height is the height of the drawable. When drawn, the line is centered in the drawable. If size height <=stroke width, the line won't show up.)

See code here: https://stackoverflow.com/a/28867281/3817964

Community
  • 1
  • 1
furnaceX
  • 567
  • 2
  • 8
  • 15
0

sp uses the scale factor of the device's font setting, rather than just the scale factor of the screen's density (dp) - don't use sp for non-text related dimensions.

FunkTheMonk
  • 10,908
  • 1
  • 31
  • 37
0

Add this following line to your AndroidManifest - application tag

android:hardwareAccelerated="false"
Dunken_sai
  • 343
  • 3
  • 7
Surendar D
  • 5,554
  • 4
  • 36
  • 38