北京高校毕业生就业突击讲座
2008-05-20 13:11
330 查看
自定义组合控件,用来复用
其一:
首先看布局文件:
一张图片,一行文字。
然后看定义的控件:
好了,这样你就可以使用了。
其二:
自定义一个EditText
首先在drawable定义一个selector,命名为selector_edittext_bg:
然后写个自定义控件的xml文件:
这个就是EditText前面有个说明文字;
接下来是定义一个控件了。
下面是使用方法:
好了,完工。具体要了解如何定义自己的属性,请看下面:
http://ericchan2012.iteye.com/admin/blogs/1650900
http://ericchan2012.iteye.com/blog/1650754
其一:
首先看布局文件:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_below="@+id/iv" android:text="@string/bless" /> </RelativeLayout>
一张图片,一行文字。
然后看定义的控件:
public class ImageBtn extends LinearLayout { private ImageView iv; private TextView tv; private LayoutInflater mInflater; public ImageBtn(Context context) { this(context, null); } public ImageBtn(Context context, AttributeSet attrs) { super(context, attrs); mInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); mInflater.inflate(R.layout.birth_cloud_item, this, true); } protected void onFinishInflate() { super.onFinishInflate(); iv = (ImageView) findViewById(R.id.iv); tv = (TextView) findViewById(R.id.tv); } public void setImageResource(int resId) { iv.setImageResource(resId); } public void setText(int resId) { tv.setText(resId); } }
好了,这样你就可以使用了。
其二:
自定义一个EditText
首先在drawable定义一个selector,命名为selector_edittext_bg:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/edit_pressed" android:state_focused="true"/> <item android:drawable="@drawable/edit_normal"/> </selector>
然后写个自定义控件的xml文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"> <TextView android:id="@+id/tv" android:textColor="#987787" android:layout_width="100dip" android:layout_height="wrap_content" android:textSize="16sp" android:text="@string/phone" /> <EditText android:id="@+id/et" android:layout_width="180dip" android:background="@drawable/selector_edittext_bg" android:layout_height="wrap_content"/> </LinearLayout>
这个就是EditText前面有个说明文字;
接下来是定义一个控件了。
public class MyEditText extends LinearLayout { private EditText et; private TextView tv; private LayoutInflater mInflater; public MyEditText(Context context) { this(context, null); } public MyEditText(Context context, AttributeSet attrs) { super(context, attrs); mInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); mInflater.inflate(R.layout.myedittext, this, true); } protected void onFinishInflate() { super.onFinishInflate(); et = (EditText) findViewById(R.id.et); tv = (TextView) findViewById(R.id.tv); } public void setText(int resId) { tv.setText(resId); } }
下面是使用方法:
<com.ds.widget.MyEditText android:id="@+id/myedittext" android:layout_width="fill_parent" android:layout_height="wrap_content" />
好了,完工。具体要了解如何定义自己的属性,请看下面:
http://ericchan2012.iteye.com/admin/blogs/1650900
http://ericchan2012.iteye.com/blog/1650754
相关文章推荐
- 2005年非上海生源高校毕业生就业进沪评分办法
- 落户上海市高校毕业生就业指导中心集体户口办理办法
- 给高校毕业生的就业建议
- 2005年非上海生源高校毕业生就业进沪评分办法
- 北京联合大学CSDN 高校俱乐部腾讯微爱讲座育慧里第二讲
- 扩大高校毕业生就业见习补贴范围_网易新闻
- 北京高校讲座信息汇总
- “引领Web 2.0技术—PHP+MySQL开发与就业前景”免费讲座(北京)
- 09年普通高校毕业生举办17场就业洽谈会
- 高校毕业生将达727万人,就业形势不容乐观
- 12月份高校毕业生上海地区专场招聘会时间表(全国人才市场第二届高校毕业生上海地区就业指导月活动)
- 高校毕业生就业状况之网友论战
- 一. 浅谈当今高校毕业生的就业形势
- 普通高校毕业生就业心情
- 国家促进普通高校毕业生就业的政策
- 我国劳动法中关于高校应届毕业生就业协议及合同的一切条款
- 报告称今年将有100万高校毕业生不能就业
- 广东高校毕业生就业真相 6成多对工作不满意(图)
- 关于加快服务外包产业发展促进高校毕业生就业的若干意见
- 高校毕业生就业状况分析报告发布