【问题标题】:Dotted line XML in AndroidAndroid中的虚线XML
【发布时间】:2015-04-25 09:33:31
【问题描述】:

我正在开发一个 Android 应用程序,我想在其中使用虚线 XML 作为布局中的分隔符。为此,我为此使用了不同的可绘制对象,但为了制作虚线,它正在制作一条线。

我的drawable如下:

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

【问题讨论】:

标签: android line dotted-line


【解决方案1】:

Dashed lines are not supported in GL mode.所以添加

android:layerType="software"

例如

<ImageView
    android:layerType="software" // add here
 ...

在您的 xml 布局中查看或以编程方式作为

view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

或者像这样关闭硬件加速:

android:hardwareAccelerated="false"

【讨论】:

  • 感谢您的回复。你能告诉我我可以把layerType放在哪里吗,你能在我的代码sn-p中显示它吗?谢谢
【解决方案2】:
use Below code

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="90"
    android:toDegrees="90" >

    <shape android:shape="line" >

        <stroke

            android:width="1dp"
            android:dashGap="6px"
            android:dashWidth="6px"
            android:color="#C7B299" />
    </shape>

</rotate>

【讨论】:

    【解决方案3】:

    也许对你有帮助..

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">
    
        <stroke
           android:color="#C7B299"
           android:dashWidth="10px"
           android:dashGap="10px" />
    </shape>
    

    只是参考这个.. How do I make a dotted/dashed line in Android?

    【讨论】:

      【解决方案4】:

      试试这个

      <?xml version="1.0" encoding="utf-8"?>
          <shape
              xmlns:android="http://schemas.android.com/apk/res/android"
              android:shape="line">
              <stroke
                  android:color="#FF404040"
                  android:width="5dp"
                  android:dashGap="10dp"
                  android:dashWidth="10dp"
                  />
      
          </shape>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-06
        相关资源
        最近更新 更多