Android開発のカスタムコントロールの属性を定義する方法

Javaコード:
public RangeSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);

// Obtain our styled custom attributes from xml
TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.RangeSeekBar);

String s = a.getString(R.styleable.RangeSeekBar_orientation);
if(s != null)
orientation = s.toLowerCase().contains(“vertical") ? VERTICAL : HORIZONTAL;

limitThumbRange = a.getBoolean(R.styleable.RangeSeekBar_limitThumbRange, true);

scaleRangeMin = a.getFloat(R.styleable.RangeSeekBar_scaleMin, 0);
scaleRangeMax = a.getFloat(R.styleable.RangeSeekBar_scaleMax, 100);
scaleStep = Math.abs(a.getFloat(R.styleable.RangeSeekBar_scaleStep, DEFAULT_STEP));

thumb = a.getDrawable(R.styleable.RangeSeekBar_thumb);

range = a.getDrawable(R.styleable.RangeSeekBar_range);

track = a.getDrawable(R.styleable.RangeSeekBar_track);

// Register desired amount of thumbs
int noThumbs = a.getInt(R.styleable.RangeSeekBar_thumbs, DEFAULT_THUMBS);
thumbWidth = a.getDimension(R.styleable.RangeSeekBar_thumbWidth, 50);
thumbHeight = a.getDimension(R.styleable.RangeSeekBar_thumbHeight, 100);
for(int i = 0; i < noThumbs; i++) {
Thumb th = new Thumb();
thumbs.add(th);
}
a.recycle();
}

Android

Posted by arkgame