AndroidUI開源組件庫BottomView 第三方自訂UI控制項

來源:互聯網
上載者:User

標籤:

 

 

    • 這裡分享一個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裡即可

       

      view sourceprint?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>另外如果提示

       

       

      view sourceprint?1.<item name="android:windowBackground">@color/white</item>這裡的white找不到的話,說明你項目res/values/color.xml沒有建立或者沒有white顏色這個值,只需在res/values/color.xml裡添加

       

       

      view sourceprint?1.<color name="white">#ffffff</color>
      這個白色值即可。

       

      另外View的動畫Theme可選,建議也複製進去,效果好一些,代碼如下:

       

      view sourceprint?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>
      res/anim/bottomview_anim_enter.xml

       

       

      view sourceprint?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>
      res/anim/bottomview_anim_exit.xml

       

       

      view sourceprint?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、部分核心使用代碼:

       

      view sourceprint?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控制項

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.