标签:
这里分享一个Android的非常经典实用而且简单方便的第三方UI控件库:BottomView(小米的米UI也用到了这个)
实现功能:
可以在底部弹出的View里自定义布局;
可以自定义是否可以触摸外部消失;
可以自定义事件;
可以自定义外围背景是否透明;
可以自定义动画;
如果需要的话,可以强制为顶部View显示
BottomView.jar库文件下载地址:http://download.csdn.net/detail/jay100500/7547055
BottomView的Demo下载地址:http://download.csdn.net/detail/jay100500/7547049
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; 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(); } }
用法:
1、下载BottomView.jar库文件,放到Android项目工程里的libs里
2、设置BottomView的Theme:
这2个Theme复制粘贴到你的项目的res/values/styles.xml里即可
01.<!--半透明背景Theme-->02.<style name="BottomViewTheme_Defalut">03.<item name="android:windowFrame">@null</item>04.<item name="android:windowContentOverlay">@null</item>05.<item name="android:windowIsFloating">true</item>06.<item name="android:windowIsTranslucent">false</item>07.<item name="android:windowNoTitle">true</item>08.<item name="android:windowBackground">@color/white</item>09.<item name="android:backgroundDimEnabled">true</item>10.<item name="android:windowFullscreen">true</item>11.</style>12.<!--透明背景Theme-->13.<style name="BottomViewTheme_Transparent">14.<item name="android:windowFrame">@null</item>15.<item name="android:windowIsFloating">true</item>16.<!-- Transparent -->17.<item name="android:windowIsTranslucent">false</item>18.<item name="android:windowContentOverlay">@null</item>19.<item name="android:windowNoTitle">true</item>20.<item name="android:windowBackground">@color/white</item>21.<item name="android:backgroundDimEnabled">false</item>22.</style>
1.<item name="android:windowBackground">@color/white</item>
1.<color name="white">#ffffff</color>
另外View的动画Theme可选,建议也复制进去,效果好一些,代码如下:
1.<style name="BottomToTopAnim" parent="android:Animation">2.<item name="@android:windowEnterAnimation">@anim/bottomview_anim_enter</item>3.<item name="@android:windowExitAnimation">@anim/bottomview_anim_exit</item>4.</style>
1.<?xml version="1.0" encoding="utf-8"?>2.<set xmlns:android="http://schemas.android.com/apk/res/android" >3. 4.<translate5.android:duration="500"6.android:fromYDelta="100%p" />7. 8.</set>
1.<?xml version="1.0" encoding="utf-8"?>2.<set xmlns:android="http://schemas.android.com/apk/res/android" >3. 4.<translate5.android:duration="500"6.android:toYDelta="100%p" />7. 8.</set>

2、部分核心使用代码:
1.BottomView bottomView = new BottomView(this,2.R.style.BottomViewTheme_Defalut, R.layout.bottom_view);3.bottomView.setAnimation(R.style.BottomToTopAnim);//设置动画,可选4.bottomView.showBottomView(false);
如果想获取这个View的话,调用.getView()方法即可。
效果图之一:(可随意发挥)
不懂的加我QQ 852041173
欢迎加入MtAndroid开发者QQ群:271410559

百度网盘备用下载地址:
BottomView.jar库文件下载地址:http://pan.baidu.com/s/1mg7eseG
BottomView的Demo下载地址:http://pan.baidu.com/s/1hqkRM8s
首发地址:http://www.aplesson.com/?p=400
AndroidUI开源组件库BottomView 第三方自定义UI控件
标签:
原文地址:http://www.cnblogs.com/exmyth/p/4579227.html