【UI】【View】自定义布局方法与注意事项(二)
2016-03-03 16:59
567 查看
本篇博客是文章的继续。
【UI】【View】自定义布局方法与注意事项(一)
3. LayoutParams
①:此代码知识点较多,另一篇博客会专门记录。
三、注意事项
1. 如果需要从XML文件中inflate控件,必须写出控件以下全部构造方法。否则会报java.lang.classnotfoundexception。
//构造方法
public CricleMenu(Context context) {
super(context);
}
public CricleMenu(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CricleMenu(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
2.在使用自定义view时,XML文件要引用全部包名,否则会报android.view.inflateException。
<com.example.custom_view_test.CricleMenu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#AA333333">
</com.example.custom_view_test.CricleMenu>
【UI】【View】自定义布局方法与注意事项(一)
3. LayoutParams
①:此代码知识点较多,另一篇博客会专门记录。
//Margin是子view相对父控件四条边的距离 @Override public ViewGroup.MarginLayoutParams generateLayoutParams(AttributeSet attrs){ return new MarginLayoutParams(getContext(), attrs); }
三、注意事项
1. 如果需要从XML文件中inflate控件,必须写出控件以下全部构造方法。否则会报java.lang.classnotfoundexception。
//构造方法
public CricleMenu(Context context) {
super(context);
}
public CricleMenu(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CricleMenu(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
2.在使用自定义view时,XML文件要引用全部包名,否则会报android.view.inflateException。
<com.example.custom_view_test.CricleMenu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#AA333333">
</com.example.custom_view_test.CricleMenu>
相关文章推荐
- GUI - Web前端开发框架
- 评价ui设计作品好坏的八个标准(界面/交互设计研究)
- 新注册
- 四大漏洞入侵博客
- 在Ubuntu系统上安装Ghost博客平台的教程
- 为Yahoo! UI Extensions Grid增加内置的可编辑器
- Cocos2d-x UI开发之文本类使用实例
- 谈谈对jquery ui tabs 的理解
- 在IE 浏览器中使用 jquery的fadeIn() 效果 英文字符字体加粗
- UI Events 用户界面事件
- jquery UI Datepicker时间控件的使用方法(基础版)
- Hallo.js基于jQuery UI所见即所得的Web编辑器
- 基于jQuery UI CSS Framework开发Widget的经验
- jquery ui 1.7 ui.tabs 动态添加与关闭(按钮关闭+双击关闭)
- jQuery UI设置固定日期选择特效代码分享
- Jquery ajax 同步阻塞引起的UI线程阻塞问题
- jQuery UI的Dialog无法提交问题的解决方法
- jQuery ui实现动感的圆角渐变网站导航菜单效果代码
- jquery UI Datepicker时间控件的使用方法(终结版)
- jquery UI Datepicker时间控件的使用方法(加强版)