目前我正在嘗試創建自己的視圖。現在我找到了有用的教程developer.android.net。我跟着介紹,但我有一些麻煩使用視圖。Android編程創建自己的視圖
首先,我的文件夾structur
cView.java
package company.firstactivity.customViews;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
public class cView extends View{
public cView(Context context, AttributeSet attrs){
super(context,attrs);
}
}
cViewAttributes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="cView">
<attr name="showText" format="boolean" />
</declare-styleable>
</resources>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="company.firstactivity.MainActivity">
</RelativeLayout>
我的問題是使用視圖的命名空間。什麼是命名空間?誰能幫我?
在此先感謝!
你是什麼意思的命名空間?那個是從哪裏來的? – PearsonArtPhoto
你的意思是你想知道如何在xml級別包含你的視圖? – thetonrifles
@PearsonArtPhoto按下鏈接,然後點:**定義自定義屬性**。 - > _而不屬於http://schemas.android.com/apk/res/android命名空間,它們屬於http://schemas.android.com/apk/res/ [你的包名] _。 – MyNewName