Professional Documents
Culture Documents
Expandable List View
Expandable List View
Expandable List View
网易 博客 摄影 发现好博客 群博客召集令 登录 注册
鹏既是我
不经历风雨,怎能见彩虹
首页 日志 相册 音乐 收藏 博友 关于我
日志
加博友 关注他
IT行业 2008-12-15 12:00:32 阅读1299 评论0 订阅 字号: 大 中 小
伤逝
---------------------------------------------------------
古文的逝去
<?xml version="1.0" encoding="utf-8"?> CPU与外设(转百度好问)
<resources> 【转载】NAND 和NOR …
<declare-styleable name="LabelView"> Relative Layout
</declare-styleable> 穿孔狂人的嘴巴最给力
</resources> 马赛:适合裸晒的地方
-------------------------------------------------------------- 震撼!美丽的自然之心
唐人街吃顿饭才45美金
(2)Define my java file of control 巨蟒剖腹竟有上百条小…
美女真空上阵演绎黄色…
----------------------------------------------------------
更多>>
public class CustomControl extends View {
Paint p = new Paint();
Color clr = null;
String text = null;
int txtSize = 0;
private int mAscent;
CharSequence s = a.getString(R.styleable.LabelView_text);
if (s != null) {
setText(s.toString());
}
int textSize = a.getDimensionPixelOffset(R.styleable.LabelView_textSize, 0);
if (textSize > 0) {
setTextSize(textSize);
}
int clr = a.getColor(R.styleable.LabelView_textColor, Color.rgb(0, 0, 0));
this.setColor(clr);
…163.com/…/2089095620081115003… 1/4
27/04/2011 User Define Control (Text View for ex…
a.recycle();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec));
}
private int measureWidth(int measureSpec) {
int result = 0;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
if (specMode == MeasureSpec.EXACTLY) {
// We were told how big to be
result = specSize;
} else {
// Measure the text
result = (int) p.measureText(text) + getPaddingLeft()
+ getPaddingRight();
if (specMode == MeasureSpec.AT_MOST) {
// Respect AT_MOST value if that was what is called for by measureSpec
result = Math.min(result, specSize);
}
}
return result;
}
…163.com/…/2089095620081115003… 2/4
27/04/2011 User Define Control (Text View for ex…
}
}
return result;
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.drawText(text, getPaddingLeft(), getPaddingTop() - mAscent, p);
}
}
------------------------------------------------------------------------
-------------------------------------
xmlns:app="http://schemas.android.com/apk/res/com.china.myapilist"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.china.myapilist.customcontrol.CustomControl
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:textColor="#ffff0000"
app:text="Red"/>
<com.china.myapilist.customcontrol.CustomControl
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:textColor="#ff0000ff"
app:text="Blue" app:textSize="20dp"/>
<com.china.myapilist.customcontrol.CustomControl
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:text="Green" app:textColor="#ff00ff00" />
<ExpandableListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:id = "@+id/mylist"
/>
</LinearLayout>
-------------------------------------------------------------------------
Effect:
…163.com/…/2089095620081115003… 3/4
27/04/2011 User Define Control (Text View for ex…
最近读者
登录后,您可以
在此留下足迹。
yjg200… igohu… 锦绣シ鈊 不再犹豫 Kevin.… 斌の少
评论
点击登录 | 昵称:
发表
网易公司版权所有 ©1997-2011
…163.com/…/2089095620081115003… 4/4