2011-11-23 50 views
2

我知道我可以在代碼中定義這個,但是可以在代碼中定義這種類型的東西嗎?是否有可能在android代碼中創建形狀

我想要創建一個形狀,並且形狀的值([「rectangle」|「oval」|「line」|「ring」])需要依賴於代碼(用戶輸入)。

這可以在代碼中完成嗎?我怎樣才能做到這一點 ?

<?xml version="1.0" encoding="utf-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape=["rectangle" | "oval" | "line" | "ring"] > 
    <corners 
     android:radius="integer" 
     android:topLeftRadius="integer" 
     android:topRightRadius="integer" 
     android:bottomLeftRadius="integer" 
     android:bottomRightRadius="integer" /> 
    <gradient 
     android:angle="integer" 
     android:centerX="integer" 
     android:centerY="integer" 
     android:centerColor="integer" 
     android:endColor="color" 
     android:gradientRadius="integer" 
     android:startColor="color" 
     android:type=["linear" | "radial" | "sweep"] 
     android:usesLevel=["true" | "false"] /> 
    <padding 
     android:left="integer" 
     android:top="integer" 
     android:right="integer" 
     android:bottom="integer" /> 
    <size 
     android:width="integer" 
     android:height="integer" /> 
    <solid 
     android:color="color" /> 
    <stroke 
     android:width="integer" 
     android:color="color" 
     android:dashWidth="integer" 
     android:dashGap="integer" /> 
</shape> 
+0

請看看這個:http://stackoverflow.com/questions/6205354/defining-drawable-shape-with-in-java-code – Lucian

回答

相關問題