Android Dash/doted line issue?

随声附和 提交于 2019-12-23 07:36:36

问题


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

Screenshots

And

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.


回答1:


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




回答2:


Try changing sp to dp to:

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



回答3:


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.




回答4:


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




回答5:


Add this following line to your AndroidManifest - application tag

android:hardwareAccelerated="false"


来源:https://stackoverflow.com/questions/18983788/android-dash-doted-line-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!