【问题标题】:Shape with outer stroke only仅具有外部笔划的形状
【发布时间】:2017-05-26 05:24:49
【问题描述】:
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
       xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <solid android:color="#ffffff"/>

    <stroke android:width="30dp"
            android:color="#51000000"
        />
</shape>

它给出了“半内半外”的笔触。 我需要的只是外部半透明笔划。可以吗?

我拥有的是

我需要的是

谢谢

【问题讨论】:

标签: android android-layout


【解决方案1】:

试试这个:(更改尺寸和颜色以满足您的需要)

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="oval">
            <stroke android:width="@dimen/default_stroke_size_small" android:color="@color/colorDimBlack"/>
        </shape>
    </item>

    <item>
        <shape android:shape="oval">
            <stroke android:width="@dimen/default_stroke_size_small" android:color="@android:color/transparent"/>
            <solid android:color="@color/colorWhite"/>
        </shape>
    </item>
</layer-list>

【讨论】:

    【解决方案2】:

    我发现除了以下方法之外别无他法:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item >
            <shape android:shape="oval">
                <solid android:color="@android:color/transparent" />
                <stroke
                    android:width="@dimen/stroke_width"
                    android:color="#33000000" />
            </shape>
        </item>
    
        <item >
            <shape android:shape="oval" >
                <solid android:color="#fff" />
                <stroke
                    android:width="@dimen/stroke_width"
                    android:color="@android:color/transparent">
                </stroke>
            </shape>
        </item>
    </layer-list>
    

    【讨论】:

      【解决方案3】:

      您可以检查使用图层列表创建的此形状及其项目。

      <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
          <item >
              <shape android:shape="oval" >
                  <solid android:color="#fff" />
              </shape>
          </item>
      
          <item >
              <shape android:shape="oval">
                  <solid android:color="@android:color/transparent" />
                  <stroke
                      android:width="50dp"
                      android:color="#30000000" />
              </shape>
          </item>
      
      </layer-list>
      

      【讨论】:

      • 这只是一个内部没有纯白色的戒指。
      • 你可以添加你想要的图片吗?
      • 它给出的是内笔画,而不是外笔画。
      • 只换颜色没有内外描边。
      • 将颜色改为#80000000并检查。
      【解决方案4】:

      这是Android studio XML preview bug。看起来像你上面显示的Android studio xml preview的图像。实际上没有内层和外层。

      【讨论】:

      【解决方案5】:

      尝试为 shape 属性添加 android:innerRadius="0dp" -

      <?xml version="1.0" encoding="utf-8"?>
      <shape android:shape="oval"
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:innerRadius="0dp"
      >
      <solid android:color="#ffffff"/>
      
      <stroke android:width="4dp"
          android:color="#51000000"
          />
      </shape>
      

      【讨论】:

      • 没有任何改变。结果完全一样。
      【解决方案6】:

      如果您为描边颜色添加 Alpha,则内半部分不透明,外半部分透明。这就是描边颜色的工作原理。如果您不希望内圈使用不带 Alpha 的颜色并调整 Hexcode。

      【讨论】:

      • 你能提供一个你从哪里得到的参考吗?
      • “内半部不透明,外半部透明”——你能看到附图吗?两半都是透明的。另外,请问您能否提供一个标记?
      【解决方案7】:

      您在第一种颜色中缺少一个f。因此它创建了一个半可见的模式

      <?xml version="1.0" encoding="utf-8"?>
      <shape android:shape="oval"
          xmlns:android="http://schemas.android.com/apk/res/android"
          >
          <solid android:color="#fffffff"/>
      
          <stroke android:width="30dp"
              android:color="#51000000"
              />
      </shape>
      

      【讨论】:

        【解决方案8】:

        将您的代码更新为:

        <?xml version="1.0" encoding="utf-8"?>
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">
            <solid android:color="#ffffff" />
        
            <stroke
                android:width="30dp"
                android:color="#000000" /> <--- this line you have to change
        </shape>
        

        【讨论】:

        • 改变输出颜色不是 OP 想要的!
        • “这条线你必须改变” - 不,我需要一个半透明的笔触。
        猜你喜欢
        • 1970-01-01
        • 2017-03-03
        • 1970-01-01
        • 2012-10-16
        • 1970-01-01
        • 2021-04-10
        • 1970-01-01
        • 1970-01-01
        • 2018-12-11
        相关资源
        最近更新 更多