먼저, 속성을 선언 : 사용자 정의 속성을 정의하면
<resources>
<declare-styleable name="PieChart">
<attr name="showText" format="boolean" />
<attr name="labelPosition" format="enum">
<enum name="left" value="0"/>
<enum name="right" value="1"/>
</attr>
</declare-styleable>
</resources>
, 당신은 레이아웃 XML 파일을 단지 같은 기본 속성에 사용할 수 있습니다. 유일한 차이점은 사용자 지정 특성이 다른 네임 스페이스에 속하는 것입니다. http://schemas.android.com/apk/res/android
네임 스페이스에 속하는 대신 http://schemas.android.com/apk/res/[your package name]
에 속합니다. 사용자 정의 PieChart
클래스에 대한이 같은
뭔가 :
public PieChart(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.PieChart,
0, 0);
try {
mShowText = a.getBoolean(R.styleable.PieChart_showText, false);
mTextPos = a.getInteger(R.styleable.PieChart_labelPosition, 0);
} finally {
a.recycle();
}
}
SOURCE : 멀어져
http://developer.android.com/training/custom-views/create-view.html
코드에서
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/com.example.customviews">
<com.example.customviews.charting.PieChart
custom:showText="true"
custom:labelPosition="left" />
</LinearLayout>
, 당신은이 라인을 따라 뭔가가 필요 . READING : 당신이 당신의 필요에 따라 사용자 정의 된 목록보기 나있는 gridview와 함께 사용자 지정 어댑터가 필요 같은
Defining custom attrs
귀하의 요구 사항 보인다. –
@AnujSharma OP는 새로운보기를 만들고 버튼 수를 결정하는 XML 속성을 정의 할 수 있습니다. 문자열 배열이나 버튼에 텍스트를 제공하는 것으로 연결되는 또 다른 XML 속성입니다. :) –