【问题标题】:Dotted line separator with custom thickness具有自定义厚度的虚线分隔符
【发布时间】:2014-01-28 06:42:24
【问题描述】:

我有一个虚线分隔符

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

    <!-- 
#17b851 #C7B299
     -->
    <stroke
       android:color="#9e9c85"
       android:dashWidth="10px"
       android:dashGap="10px" 
       />
</shape>

现在它几乎看不见。我怎样才能使它变厚。我试着给 android:height="2px" & android:dashHeight="5px" 但它没有工作。

【问题讨论】:

    标签: android xml paint stroke


    【解决方案1】:

    笔划宽度必须小于高度。

    (笔划宽度是线条的宽度。大小高度是drawable的高度。绘制时,线条在drawable中居中。如果大小高度

    dottedline.xml:

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="line" >
    
        <stroke
            android:dashGap="3dp"
            android:dashWidth="3dp"
            android:width="2dp"
            android:color="@android:color/black" />
    
        <size android:height="3dp" />
    </shape>
    

    布局xml:

    <ImageView
            android:layerType="software"
            android:contentDescription="underline"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/dottedline" />
    

    【讨论】:

    • 另外,(没有大小高度)ImageView 中的 layout_height 可以设置为大于笔划宽度的值,它也应该可以工作。
    【解决方案2】:

    你可以使用笔画宽度,

    android:width="3dp"
    

    快照

    【讨论】:

    • @Justin 工作正常。如果它对你不起作用并不意味着它对其他人不起作用。为什么这被否决了
    • @Justin 您基于什么得出这样的结论是行不通的。你的代码在哪里不起作用?如果它不起作用,则不会被接受
    • 这对我也不起作用。虚线在布局编辑器中正确显示,但在设备上不可见。将 layerType 设置为 software 也无济于事,这是一种常见的修复方法。
    • @McLovin 确实对我有用。除此之外,我不太了解并发布您所做的事情以及您尝试了哪些版本
    • @McLovin 如果它不起作用,您需要更具体。还有其他解决方案,您可以在画布上绘制虚线
    【解决方案3】:

    这样使用它是使用完整的和这个DOTTED LINE IN ANDROID

    EDIT :Here is Answer

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
     android:shape="line" >
    
       <solid android:color="#fdfdfd" >
       </solid>
    
     <stroke
      android:dashGap="5px"
      android:dashWidth="5px"
      android:width="2dp"
      android:color="@color/scoreColor" >
    </stroke>
    
    </shape>
    

    在xml文件中使用这个

    NOTE :注意:在更高版本中没有此行无法正常工作 android:layerType="software"

     <View
        android:layout_width="match_parent"
        android:layout_height="5dip"
        android:background="@drawable/dash_line"
        android:layerType="software"
        android:orientation="vertical" />
    

    【讨论】:

    • 添加这一行 android:layerType="software" 解决了所有设备上的问题。
    【解决方案4】:

    你可以定义一行像

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
     android:shape="line">
    
     <stroke
    android:dashGap="3dp"
    android:dashWidth="8dp"
    android:height="2px"
    android:color="#E90C0C" />
    
    </shape>
    

    并在你的视图中使用它

    <View
        android:id="@+id/vDottedLine"
        android:background="@drawable/dotted"
        android:layout_width="match_parent"
        android:layout_height="2px"
        android:layerType="software" />
    

    【讨论】:

      猜你喜欢
      • 2011-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-21
      • 2021-12-04
      • 1970-01-01
      相关资源
      最近更新 更多