2015-03-31 52 views
0

,所以我試圖做這個教程http://code.tutsplus.com/tutorials/android-sdk-creating-custom-views--mobile-14548創建一個自定義視圖按鈕,這樣我可以讓我得到一個錯誤在屏幕上繪製的粉圓這就是當我嘗試做這裏的教程是主要的文件。獲得一個錯誤的XML解析:綁定前綴

public class Main extends ActionBarActivity { 
    Draw v; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 


     LinearLayout layout1 = new LinearLayout (this); 
     FrameLayout game = new FrameLayout(this); 
     Draw v = new Draw (this, null); 

     game.addView(v); 
     game.addView(layout1); 
     setContentView(game); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 
} 

這裏是XML文件這就是即時得到錯誤

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:custom="http://schemas.android.com/apk/res/com.Tripps.test.Draw" 
    xmlns:Tripps="http://schemas.android.com/apk/res/com.Tripps.test" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.Tripps.test.Main" > 

    <com.Tripps.test.Draw 
    android:id="@+id/custView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_margin="5dp" 
    custom:circleColor="#ff0099" 
    custom:circleLabel="Hello" 
    custom:labelColor="#ffff66" 
    </com.Tripps.test.Draw> 

</RelativeLayout> 

這裏是一個擴展viewc這個繪圖類是什麼,我想引用

public class Draw extends View { 


    //circle and text colors 
    private int circleCol, labelCol; 
    //label text 
    private String circleText; 
    //paint for drawing custom view 
    private Paint circlePaint; 


    public Draw(Context context, AttributeSet attrs){ 
     super(context, attrs); 
     //paint object for drawing in onDraw 
     circlePaint = new Paint(); 
     //get the attributes specified in attrs.xml using the name we included 
     TypedArray a = context.getTheme().obtainStyledAttributes(attrs, 
      R.styleable.DrawV, 0, 0); 
    } 
     @Override 
     protected void onDraw(Canvas canvas) {; 

     } 
} 

這裏是教程告訴我在值文件夾中執行一個名爲attr的文件。在我不知道爲什麼,但我把它放在那裏

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <declare-styleable name="Draw"> 
    <attr name="circleColor" format="color" ></attr> 
    <attr name="circleLabel" format="string"></attr> 
    <attr name="labelColor" format="color"></attr> 
</declare-styleable> 
</resources> 

回答

1

教程告訴我做了一個名爲ATTR中的值文件夾文件。在 的我不知道爲什麼,但我把它放在那裏

要使用自定義視圖自定義屬性,在attrs.xml文件中添加的所有屬性。

res/values文件夾中創建attrs.xml文件。

+0

現在有一個錯誤說「找到的包com.Tripp.Draw屬性‘circleColor’沒有資源標識符 – 2015-03-31 04:42:11

相關問題