简体   繁体   English

解析XML时出错:未绑定前缀

[英]Getting an error parsing xml: unbound prefix

so i am trying to do this tutorial http://code.tutsplus.com/tutorials/android-sdk-creating-custom-views--mobile-14548 to create a custom view button so that i can make the pink circle thats drawn on the screen i am getting an error when i try to do the tutorial here is the main file. 因此,我尝试执行本教程http://code.tutsplus.com/tutorials/android-sdk-creating-custom-views--mobile-14548创建自定义视图按钮,以便我可以绘制出粉红色的圆圈在屏幕上,当我尝试执行教程时出现错误,这里是主文件。

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);
    }
}

here is the XML file for that this is where im getting the error 这是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>

here is the Draw class that extends viewc this is what i am trying to reference 这是扩展viewc的Draw类,这是我尝试引用的内容

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) {;

       }
}

and here is what the tutorial told me to do its a file called attr in the values folder. 这是本教程告诉我的,它在values文件夹中执行一个名为attr的文件。 in the i dont know why but i put it there 在我不知道为什么,但我把它放在那里

<?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>

tutorial told me to do its a file called attr in the values folder. 教程告诉我在values文件夹中执行一个名为attr的文件。 in the i dont know why but i put it there 在我不知道为什么,但我把它放在那里

To use custom attributes for custom view, add all attributes in attrs.xml file. 要将自定义属性用于自定义视图,请在attrs.xml文件中添加所有属性。

Create attrs.xml file inside res/values folder. res/values文件夹中创建attrs.xml文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM