2017-08-11 118 views
0

我想在android中繪製這樣的形狀。Android - 如何繪製一個透明的矩形邊框形狀,只有其角落可見?

enter image description here

我用下面的代碼

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/shape_my"> 
<stroke 
    android:width="2dp" 
    android:dashWidth="20dp" 
    android:dashGap="20dp" 
    android:color="#c1c1c1" /> 
<padding 
    android:bottom="20dp" 
    android:left="20dp" 
    android:right="20dp" 
    android:top="20dp" /> 
<corners android:radius="0dp" /> 
<solid android:color="#00000000" /> 
</shape> 

但是,沒有完美的我。幫助我,朋友。

回答

0
<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <solid android:color="@color/transparent" /> 
    <stroke 
     android:width="1.5dp" 
     android:color="@color/white" /> 
    <padding 
     android:bottom="5dp" 
     android:left="5dp" 
     android:right="5dp" 
     android:top="5dp" /> 
    <corners 
     android:bottomLeftRadius="5dp" 
     android:bottomRightRadius="5dp" 
     android:topLeftRadius="5dp" 
     android:topRightRadius="5dp" /> 
</shape> 
0
<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
<item 
    android:bottom="1dp" 
    android:left="-2dp" 
    android:right="-2dp" 
    android:top="-2dp"> 
    <shape android:shape="rectangle" > 
     <stroke 
      android:width="1dp" 
      android:color="#FF000000" /> 

     <solid android:color="#00FFFFFF" /> 

     <padding android:left="10dp" 
      android:right="10dp" 
      android:top="10dp" 
      android:bottom="10dp" /> 
    </shape> 
</item> 

0

這裏是你要與跳過邊框爲白色,幾乎毫無例外的。我使用圖層列表來實現它。你應該嘗試一下,如果你需要中心透明

enter image description here

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:width="300dp" 
     android:height="300dp"> 
     <shape android:shape="rectangle"> 
      <stroke 
       android:width="15px" 
       android:color="#000000" /> 
      <solid android:color="#00000000" /> 
     </shape> 
    </item> 
    <item 
     android:width="8dp" 
     android:bottom="35dp" 
     android:top="35dp"> 
     <shape android:shape="rectangle"> 
      <solid android:color="#FFFFFF" /> 
     </shape> 
    </item> 
    <item 
     android:width="8dp" 
     android:bottom="35dp" 
     android:gravity="right" 
     android:top="35dp"> 
     <shape android:shape="rectangle"> 
      <solid android:color="#FFFFFF" /> 
     </shape> 
    </item> 
    <item 
     android:height="8dp" 
     android:gravity="top" 
     android:left="35dp" 
     android:right="35dp" 
     android:top="-1dp"> 
     <shape android:shape="rectangle"> 
      <solid android:color="#FFFFFF" /> 
     </shape> 
    </item> 
    <item 
     android:height="8dp" 
     android:gravity="bottom" 
     android:left="35dp" 
     android:right="35dp"> 
     <shape android:shape="rectangle"> 
      <solid android:color="#FFFFFF" /> 
     </shape> 
    </item> 
</layer-list> 
+0

感謝@Divyang。但我想那白線是透明的太..只有角落需要是可見的。 –

+0

然後這可能使用Vector Drawable https://developer.android.com/guide/topics/graphics/vector-drawable-resources.html –

相關問題