AndroidUI开源组件库BottomView 第三方自定义UI控件
这里分享一个Android的非常经典实用而且简单方便的第三方UI控件库:BottomView(小米的米UI也用到了这个)
原文 http://blog.csdn.net/opzoonzhuzhengke/article/details/35230819
实现功能:
可以在底部弹出的View里自定义布局;
可以自定义是否可以触摸外部消失;
可以自定义事件;
可以自定义外围背景是否透明;
可以自定义动画;
如果需要的话,可以强制为顶部View显示
BottomView.jar库文件下载地址:http://download.csdn.net/detail/jay100500/7547055
BottomView的Demo下载地址:http://download.csdn.net/detail/jay100500/7547049
其实原理就是WindowManager Dialog 和Animation的组合
这里分享一个Android的非常经典实用而且简单方便的第三方UI控件库:BottomView(小米的米UI也用到了这个)
实现功能:
可以在底部弹出的View里自定义布局;
可以自定义是否可以触摸外部消失;
可以自定义事件;
可以自定义外围背景是否透明;
可以自定义动画;
如果需要的话,可以强制为顶部View显示
用法:
1、下载BottomView.jar库文件,放到Android项目工程里的libs里
2、设置BottomView的Theme:
这2个Theme复制粘贴到你的项目的res/values/styles.xml里即可
- <!--半透明背景Theme-->
- <style name="BottomViewTheme_Defalut">
- <item name="android:windowFrame">@null</item>
- <item name="android:windowContentOverlay">@null</item>
- <item name="android:windowIsFloating">true</item>
- <item name="android:windowIsTranslucent">false</item>
- <item name="android:windowNoTitle">true</item>
- <item name="android:windowBackground">@color/white</item>
- <item name="android:backgroundDimEnabled">true</item>
- <item name="android:windowFullscreen">true</item>
- </style>
- <!--透明背景Theme-->
- <style name="BottomViewTheme_Transparent">
- <item name="android:windowFrame">@null</item>
- <item name="android:windowIsFloating">true</item>
- <!-- Transparent -->
- <item name="android:windowIsTranslucent">false</item>
- <item name="android:windowContentOverlay">@null</item>
- <item name="android:windowNoTitle">true</item>
- <item name="android:windowBackground">@color/white</item>
- <item name="android:backgroundDimEnabled">false</item>
- </style>
复制代码
另外如果提示
- <item name="android:windowBackground">@color/white</item>
复制代码
这里的white找不到的话,说明你项目res/values/color.xml没有新建或者没有white颜色这个值,只需在res/values/color.xml里添加
- <color name="white">#ffffff</color>
复制代码
这个白色值即可。
另外View的动画Theme可选,建议也复制进去,效果好一些,代码如下:
- <font color="#333333"><font face="Arial"> <style name="BottomToTopAnim" parent="android:Animation">
- <item name="@android:windowEnterAnimation">@anim/bottomview_anim_enter</item>
- <item name="@android:windowExitAnimation">@anim/bottomview_anim_exit</item>
- </style></font></font>
复制代码
res/anim/bottomview_anim_enter.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android" >
- <translate
- android:duration="500"
- android:fromYDelta="100%p" />
- </set>
复制代码
res/anim/bottomview_anim_exit.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android" >
- <translate
- android:duration="500"
- android:toYDelta="100%p" />
- </set>
复制代码
整体为:

2、部分核心使用代码:
- BottomView bottomView = new BottomView(this,
- R.style.BottomViewTheme_Defalut, R.layout.bottom_view);
- bottomView.setAnimation(R.style.BottomToTopAnim);//设置动画,可选
- bottomView.showBottomView(false);
复制代码
如果想获取这个View的话,调用.getView()方法即可。
效果图之一:(可随意发挥)

以下是源代码“:
package com.tandong.bottomview; import java.util.ArrayList; import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView; import com.tandong.bottomview.adapter.BVAdapter;
import com.tandong.bottomview.view.BottomView; /**
* BottomView
*
* www.aplesson.com
*
* @author TanDong
*
*/ public class MainActivity extends Activity implements OnClickListener {
private Button btn_show;
private ListView lv_menu_list;
private ArrayList<String> menus;
private BottomView bottomView; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); initView();
initData(); } private void initData() {
menus = new ArrayList<String>();
menus.add(getResources().getString(R.string.menu_search));
menus.add(getResources().getString(R.string.menu_filemanage));
menus.add(getResources().getString(R.string.menu_downloadmanage));
menus.add(getResources().getString(R.string.menu_setting));
menus.add(getResources().getString(R.string.menu_about)); } private void initView() {
btn_show = (Button) this.findViewById(R.id.btn_show);
btn_show.setOnClickListener(this);
} @Override
public void onClick(View arg0) {
switch (arg0.getId()) {
case R.id.btn_show:
bottomView = new BottomView(MainActivity.this,
R.style.BottomViewTheme_Defalut, R.layout.bottom_view);
bottomView.setAnimation(R.style.BottomToTopAnim); bottomView.showBottomView(false);
lv_menu_list = (ListView) bottomView.getView().findViewById(
R.id.lv_list);
BVAdapter adapter = new BVAdapter(MainActivity.this, menus);
lv_menu_list.setAdapter(adapter);
lv_menu_list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
bottomView.dismissBottomView(); }
});
break; default:
break;
}
} }
package com.tandong.bottomview.adapter; import java.util.ArrayList; import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView; import com.tandong.bottomview.R; /**
* BottomView
*
* @author TanDong
*
*/
public class BVAdapter extends BaseAdapter {
private Context c;
private ArrayList<String> alss; public BVAdapter(Context context, ArrayList<String> als) {
this.c = context;
this.alss = als;
} @Override
public int getCount() {
// TODO Auto-generated method stub
return alss.size();
} @Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return alss.get(arg0);
} @Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
} @Override
public View getView(int position, View convertView, ViewGroup arg2) {
convertView = View.inflate(c, R.layout.item, null);
TextView tv = (TextView) convertView.findViewById(R.id.tv_name);
tv.setText(alss.get(position));
return convertView;
} }
原理:
package com.tandong.bottomview.view; import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams; public class BottomView
{
private View convertView;
private Context context;
private int theme;
private Dialog bv;
private int animationStyle;
private boolean isTop = false; public BottomView(Context c, int theme, View convertView)
{
this.theme = theme;
this.context = c;
this.convertView = convertView;
} public BottomView(Context c, int theme, int resource) {
this.theme = theme;
this.context = c;
this.convertView = View.inflate(c, resource, null);
} public void showBottomView(boolean CanceledOnTouchOutside) {
if (this.theme == 0)
this.bv = new Dialog(this.context);
else
this.bv = new Dialog(this.context, this.theme); this.bv.setCanceledOnTouchOutside(CanceledOnTouchOutside);
this.bv.getWindow().requestFeature(1);
this.bv.setContentView(this.convertView);
Window wm = this.bv.getWindow();
WindowManager m = wm.getWindowManager();
Display d = m.getDefaultDisplay();
WindowManager.LayoutParams p = wm.getAttributes();
p.width = (d.getWidth() * 1);
if (this.isTop)
p.gravity = 48;
else
p.gravity = 80; if (this.animationStyle != 0)
{
wm.setWindowAnimations(this.animationStyle);
}
wm.setAttributes(p);
this.bv.show();
} public void setTopIfNecessary() {
this.isTop = true;
} public void setAnimation(int animationStyle) {
this.animationStyle = animationStyle;
} public View getView() {
return this.convertView;
} public void dismissBottomView() {
if (this.bv != null)
this.bv.dismiss();
}
}
AndroidUI开源组件库BottomView 第三方自定义UI控件的更多相关文章
- Android 开源组件 ----- Android LoopView无限自动轮转控件
Android 开源组件 ----- Android LoopView无限自动轮转控件 2015-12-28 15:26 by 杰瑞教育, 32 阅读, 0 评论, 收藏, 编辑 一.组件介绍 App ...
- cocos2d-js 3.0 rc2 自定义UI控件组件 例子:能播放动画的MenuItem。MenuItemSprite的bug
其实总体自定义UI组件都比较简单,尤其是cocos2d-js是开源的,如果有什么不明白的直接看js代码或者C++代码即可.当然js代码基本就够了. 另外,js的ctor函数虽然说是构造函数,但毕竟不是 ...
- WPF 自定义UI控件学习
最近项目中运用到了WPF处理三维软件,在C/S结构中WPF做UI还是有很多优越性,简单的学了一点WPF知识,成功的完成项目目标.项目过度阶段对于WPF的一些基本特点有了进一步了解 .至此花费一点时间研 ...
- [js开源组件开发]js手机端浮层控件,并有多种弹出小提示,兼容pc端浏览器
js dialog组件,包含alert和confirm的实现 本组件所有的资源均在github上可以查看源代码 GitHub 本dialog的组件的例子请在这里查看 demo dialog js di ...
- [js开源组件开发]js多选日期控件
js多选日期控件 详情请见:http://www.lovewebgames.com/jsmodule/calendar.html 它的github地址:https://github.com/tianx ...
- iOS开发UI篇—Quartz2D(自定义UIImageView控件)
iOS开发UI篇—Quartz2D(自定义UIImageView控件) 一.实现思路 Quartz2D最大的用途在于自定义View(自定义UI控件),当系统的View不能满足我们使用需求的时候,自定义 ...
- 面试题汇总--数据储存/应用程序/UI控件/客户端的安全性与框架处理。。。
一 数据储存 1.如果后期需要增加数据库中的字段怎么实现,如果不使用 CoreData 呢?编写 SQL 语句来操作原来表中的字段1)增加表字段ALTER TABLE 表名 ADD COLUMN 字 ...
- UI控件初始化问题:initWithFrame和initWithCoder、aweakFromNib的执行
在iOS学习和程序开发过程中,我们经常会遇到一些自定义UI控件或控制器在初始化时出现问题,尤其在大家刚开始接触时,几种初始化方法的作用以及调用的时机往往容易混淆,这也跟我们对iOS程序设计中,类的创建 ...
- GearCase UI - 自己构建一套基于 Vue 的简易开源组件库
最近 1 ~ 2 月除了开发小程序之外,还一直在继续深入的学习 Vuejs.利用零碎.闲暇的时间整合了一套基于 Vue 的 UI 组件库.命名为 GearCase UI,意为齿轮盒.现在把该项目进行开 ...
随机推荐
- Http 辅助类
using System; using System.Drawing; using System.IO; using System.Net; using System.Net.Cache; using ...
- php function_name($type=0,$order_ids='',$flag=2)
$order_ids='',表示$order_ids是字符串,不是数组 foreach ($order_ids as $key=>$order_id){ //TODO} 这 ...
- ajax分页实现,jquery.pagination.js
1.前台使用ajax无刷新分页,主要需要生成分页的工具条,这里使用的是jquery.pagination.js 插件参数可以参考----张龙豪-jquery.pagination.js分页 下面贴出代 ...
- PHP 初学者的学习线路和建议【1】
先来看下PHP初学者的学习线路: (1) 熟悉HTML/CSS/JS等网页基本元素,完成阶段可自行制作简单的网页,对元素属性相对熟悉. (2) 理解动态语言的概念和运做机制,熟悉基本的PHP语法. ( ...
- preventDefault() 方法 取消掉与事件关联的默认动作
前几天写的 响应键盘的图片切换 中, 键盘总是让浏览器滚动,为了取消掉默认的事件,使用了 preventDefault() 方法 定义和用法 preventDefault() 方法取消事件的默认动作. ...
- 武汉科技大学ACM:1007: 陶陶摘苹果
Problem Description 厘米高的板凳,当她不能直接用手摘到苹果的时候,就会踩到板凳上再试试. 个苹果到地面的高度,以及陶陶把手伸直的时候能够达到的最大高度,请帮陶陶算一下她能够摘到的苹 ...
- Java中的List(转)
List包括List接口以及List接口的所有实现类.因为List接口实现了Collection接口,所以List接口拥有Collection接口提供的所有常用方法,又因为List是列表类型,所以Li ...
- 关于C++条件运算符(三目运算符)右结合的说明
C++条件运算符 a ? c : d;是右结合的,但是这个右结合要怎么理解呢? 对于a ? b : c ? d : e; 这样的表达式如果按照右结合来解读的话,那不应该是先运算c,然后返回d或者e,返 ...
- Oracle数据库之PL/SQL流程控制语句
Oracle数据库之PL/SQL流程控制语句 在任何计算机编程语言(如C,Java,C#等)都有各种流程控制语句,同样,在PL/SQL中也存在这样的流程控制结构. 几种常见的流程控制结构: 一.条件结 ...
- JavaScript获取Select下拉框Option的Value和Text值的方法
Js获取select下拉列表框各个Option的Value值相对比较容易,不过获取Text值却有点麻烦,对于一个初学JavaScript的 新手来说,可能一时还无从下手,那么就请看下本文的方法,以一个 ...