"Most hated those not open source" Xiaomi's rice UI Bottomview source Perfect Decompile

Source: Internet
Author: User

The principle is the combination of WindowManager Dialog and animation.


Here's a very classic, practical and easy-to-use third-party UI Control library for Android: Bottomview (This is also used by Xiaomi's rice UI)

Implementation features:

You can customize the layout in the view that pops up at the bottom;

You can customize whether you can touch the outside to disappear;

Custom events can be customized;

You can customize whether the peripheral background is transparent or not;

You can customize the animation;

If necessary, you can force the display of the top view



Usage:

1. Download the Bottomview.jar library file and put it in the Libs of Android project

2, set the Bottomview theme:

Copy and paste the 2 theme into your project's Res/values/styles.xml



  1. <!--translucent background theme-->
  2. <style name= "Bottomviewtheme_defalut" >
  3. <item name= "Android:windowframe" > @null </item>
  4. <item name= "Android:windowcontentoverlay" > @null </item>
  5. <item name= "Android:windowisfloating" >true</item>
  6. <item name= "Android:windowistranslucent" >false</item>
  7. <item name= "Android:windownotitle" >true</item>
  8. <item name= "Android:windowbackground" > @color/white</item>
  9. <item name= "android:backgrounddimenabled" >true</item>
  10. <item name= "Android:windowfullscreen" >true</item>
  11. </style>
  12. <!--Transparent Background 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>
Copy Code
also if prompted
    1. <item name= "Android:windowbackground" > @color/white</item>
Copy Code
If White is not found here, your project Res/values/color.xml no new or white color value, just add it in Res/values/color.xml
    1. <color name= "White" > #ffffff </color>
Copy Code
This white value can be.

In addition, the view animation theme optional, the proposal also copied in, the effect is better, the code is as follows:

    1. <font color= "#333333" ><font face= "Arial" > <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></font></font>
Copy CodeRes/anim/bottomview_anim_enter.xml
    1. <?xml version= "1.0" encoding= "Utf-8"?>
    2. <set xmlns:android= "Http://schemas.android.com/apk/res/android" >

    3. <translate
    4. android:duration= "500"
    5. Android:fromydelta= "100%p"/>

    6. </set>
Copy Code
Res/anim/bottomview_anim_exit.xml
    1. <?xml version= "1.0" encoding= "Utf-8"?>
    2. <set xmlns:android= "Http://schemas.android.com/apk/res/android" >

    3. <translate
    4. android:duration= "500"
    5. Android:toydelta= "100%p"/>

    6. </set>
Copy Code


the whole is:



2, some core use code:


    1. Bottomview Bottomview = new Bottomview (This,
    2. R.style.bottomviewtheme_defalut, R.layout.bottom_view);
    3. Bottomview.setanimation (R.style.bottomtotopanim);//Set animation, optional
    4. Bottomview.showbottomview (FALSE);
Copy Code


If you want to get this view, call the. GetView () method.

One: (Free to play)



The following is the source code:

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;@ overrideprotected 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);} @Overridepublic 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 () {@Overridepublic 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 {pri Vate context c;private arraylist<string> alss;public bvadapter (context context, arraylist<string> als) { THIS.C = CONTEXT;THIS.ALSS = als;} @Overridepublic int GetCount () {//TODO auto-generated method Stubreturn alss.size ();} @Overridepublic Object getItem (int arg0) {//TODO auto-generated method Stubreturn Alss.get (arg0);} @Overridepublic long getitemid (int arg0) {//TODO auto-generated method Stubreturn arg0;} @Overridepublic 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;}} 



Principle:


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.con    Text);    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 (); }}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.