2017-05-13 45 views
1

我需要幫助爲Android佈局創建Arc Shape。我不需要此代碼。如果有可能使用形狀,它會很好。Arc Layout對於Android佈局可繪製

實例應用:

<LinearLayout android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/arc"> 
</LinearLayout> 

佈局想是這樣的: layout arc drawable

回答

2

這不是完全清楚你的圓弧形狀的要求是什麼,但你可以實現上述使用VectorDrawable:

arc.xml(在res /可繪/)

<?xml version="1.0" encoding="utf-8"?> 
<vector xmlns:android="http://schemas.android.com/apk/res/android" 
     android:width="223dp" 
     android:height="237dp" 
     android:viewportWidth="223" 
     android:viewportHeight="237"> 

    <path 
     android:fillColor="#757491" 
     android:strokeWidth="1" 
     android:pathData="M44,3 L0,228 C0,228 68,239 114,236 C151,236 223,221 223,221 L197,0 
C197,5.68434189e-14 158,11.7434499 120,11 C82,10.2565501 44,3 44,3 Z" /> 
</vector> 

然後你有以上:

<LinearLayout android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/arc"> 
</LinearLayout> 

注意,這裏使用VectorDrawables時(API 21+),也可以使用支持庫,以反向移植的功能,如果你需要支持較早的API級別是平臺的限制。

我是如何製作上述代碼的?我在矢量包(Sketch/Illustrator/etc)中追蹤出形狀,並將其導出爲svg文件。然後,我使用https://inloop.github.io/svg2android/上的非常方便的工具將其轉換爲VectorDrawable代碼。

如果你需要更多的東西動態然後我個人只是在Java中創建一個自定義DrawableCanvas使用Path畫,但你表示你不希望這樣做。