Android几种自定义view,优化UI
来源:互联网 发布:淘宝模特拍照软件 编辑:程序博客网 时间:2024/05/08 20:20
一,自定义listview,gridview,实现在scrollview中的滚动,重写onMeasure方法,使listview,gridview不能自身滑动
核心代码:
public class MyListView extends ListView{
public MyListView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public MyListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
二、自定义弹出进度对话框progressdialog
核心代码:
public static CustomProgressDialog createDialog(Context context) {
mCustomProgressDialog = new CustomProgressDialog(context,
R.style.CustomProgressDialog);
mCustomProgressDialog.setContentView(R.layout.progressdialog_style);
mCustomProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
return mCustomProgressDialog;
}
//为dialog中的imageview添加帧动画
public void onWindowFocusChanged(boolean hasFocus) {
if (mCustomProgressDialog == null) {
return;
}
ImageView imageView = (ImageView) mCustomProgressDialog
.findViewById(R.id.image_loading_view);
AnimationDrawable animationDrawable = (AnimationDrawable) imageView
.getBackground();
animationDrawable.start();
}
public CustomProgressDialog setMessage(String strMessage) {
TextView tvMsg = (TextView) mCustomProgressDialog
.findViewById(R.id.text_loading_msg);
if (tvMsg != null) {
tvMsg.setText(strMessage);
}
return mCustomProgressDialog;
}
三、自定义进度条progressbar
更改进度条的背景:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/progress_bg_holo_dark"
>
</item>
<item android:id="@android:id/secondaryProgress">
<clip android:drawable="@drawable/progress_secondary_holo_dark"/>
</item>
<item android:id="@android:id/progress"
>
<clip android:drawable="@drawable/progress_primary_holo_dark">
</clip>
</item>
</layer-list>
更改thumb的样式:
<!-- 按下状态 -->
<item
android:state_pressed="true"
android:drawable="@drawable/seek_thumb" />
<!-- 普通无焦点状态 -->
<item
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/seek_thumb" />
四、自定义notifycation通知栏
核心代码:
//设置RemoteViews内容,layoutId自己定义
remoteViews=new RemoteViews(activity.getPackageName(),R.layout.music_notification);
//点击通知返回主界面,通过隐式intent给通知栏中的view添加单击事件
Intent intentBack=new Intent(activity,MainActivity.class);
PendingIntent pIntent=PendingIntent.getActivity(activity, 0, intentBack, 0);
remoteViews.setOnClickPendingIntent(R.id.song_pic, pIntent);
builder.setContent(remoteViews);
builder.setSmallIcon(R.drawable.app_icon);
builder.setTicker("简单云音乐正在播放");
Notification mNotification=builder.build();
//获得完整的通知栏布局(没有这行代码,通知栏显示的是Android默认的高度,加载不完整)
mNotification.bigContentView=remoteViews;
nManager.notify(0, mNotification);
- Android几种自定义view,优化UI
- Android 几种自定义View
- android自定义view的几种方式
- android自定义view复用UI
- 【UI布局优化】Android布局优化的几种方式
- 【Android Training UI】创建自定义的Views(Lesson 4 - 优化View的性能)
- Android自定义View实现的几种方式
- 自定义View--------Android UI模板设计
- 【自定义View系列】android的UI结构
- 自定义View----Android UI模板设计
- android UI 自定义View 的详细介绍
- 【Android UI】Android开发之View的几种布局方式及实践
- Android内存优化--自定义Adapter复用View
- UI 自定义view
- UI篇 -- 自定义view
- UI之自定义View
- android自定义view课程之view的优化
- 自定义View的几种方法
- About speech
- Android 访问 WSDL 接口复习
- 在windows下的eclipse中编写consumer
- html5中列表元素
- 【Stl学习笔记】String
- Android几种自定义view,优化UI
- Python 运算符
- 枚举类
- ubuntu 16.04 LAMP环境手动配置以及问题解析
- ios常用技术 - UIDatePicker时间选择器基础
- 判断语句
- PL/SQL中LIKE函数使用变量 PL/SQL中LIKE函数使用变量
- 安装Dubbo注册中心(Zookeeper-3.4.6)
- mysql表名忽略大小写配置