Learning and using new components----the flowers

Source: Internet
Author: User

"Reprint Please specify Source: http://blog.csdn.net/feiduclear_up/article/details/46619637 csdn Ruins of the tree"

Today to learn to summarize, after Android add some new components and UI effects, Material Dialog,swiperefreshlayout,listpopupwindow,popupmenu and so on.

Material Dialog

Are you still using Material Dialog to refer to a third party's library package? Now tell you a good news, in fact, Android in the V7 package has implemented a Material-style dialog box, and compatible with the end version. You only need to use the dialog in V7 in your code to achieve a slice effect. The code is as follows:

private void ShowDialog1 () {Android. Support. V7. App. Alertdialog. BuilderBuilder = new Alertdialog. Builder(this);Builder. Setmessage("Let's fly together, I'll take you with you, take the money, take a walk on a trip"). Setnegativebutton("Cancel", null). Setpositivebutton("OK", null). Settitle("Material Design Dialog"). Show();}

is not very good, and the previous dialog use no difference, mom no longer worry about I use Material Dialog dialog box.

Swiperefreshlayout

Originally Google has implemented the Material design style of the drop-down refresh component, this new component Swiperefreshlayout is viewgroup under the V4 package, you just need to use as follows:

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http// Schemas.android.com/apk/res/android "xmlns:app=" Http://schemas.android.com/apk/res-auto " android:id="@+id/swipe_container"android:layout_width="Match_parent"  Android:layout_height="Match_parent">                    <!--sliding components such as scrollview,listview,gridview, etc. --    <ScrollViewandroid:layout_width="Match_parent"android:layout_height ="Wrap_content">                    <!--Add your own content-    </ScrollView></android.support.v4.widget.SwipeRefreshLayout>

The drop-down refresh effect is achieved by wrapping a sliding component under the Swiperefreshlayout component. Then use the following in the Java code:

Swiperefreshlayout = Findview (R. ID. Swipe_container);Setting the drop-down Refresh listener event Swiperefreshlayout. Setonrefreshlistener(this);Sets the color of the progress bar Swiperefreshlayout. Setcolorschemecolors(Color. RED, Color. BLUE, Color. GREEN);Set the circular progress bar size Swiperefreshlayout. SetSize(Swiperefreshlayout. LARGE);Set progress bar background color swiperefreshlayout. Setprogressbackgroundcolorschemecolor(Color. Dkgray);Set the drop-down distance and start refreshing the data swiperefreshlayout. Setdistancetotriggersync( -);

These include the following common methods:

    1. Setcolorschemecolors () sets the progress bar color, can set multiple values, the progress bar color changes between these multiple color values
    2. SetSize () Sets the size of the round progress bar that appears in the drop-down, with two values: Swiperefreshlayout.default and Swiperefreshlayout.large
    3. Setprogressbackgroundcolorschemecolor () Sets the background color of the circular progress bar.
    4. Setdistancetotriggersync () sets the amount of distance after which the gesture action is pulled to start refreshing the data

Summary: Of course, swiperefreshlayout components have a lot of shortcomings, such as no pull-up refresh this feature, but the online has been someone to achieve this effect, want to be able to search their own online.

Linearlayoutcompat

Recently in the V7 package suddenly found Linearlayoutcompat components, in curiosity, Baidu has a role of this component: for the linerlayout in the sub-element between item set the interval line , as follows:


Are you still bothering to add a split line to each linerlayout item element? Tell you, don't worry! Android gives you ready-made components that you can simply configure. The code reference is as follows:

<android.support.v7.widget.LinearLayoutCompatandroid:layout_width="Match_parent"  android:layout_height= "wrap_content"android:layout_gravity="Center|center_ Horizontal "android:orientation=" vertical "app:divider=" @drawable/line "  app:dividerpadding="25DP"app:showdividers="Middle|beginning|end" >                                                                                                <TextView                Android:id="@+id/textview"                Android:layout_width="Match_parent"                Android:layout_height="Wrap_content"                android:layout_gravity="Center"                android:gravity="Center"                Android:paddingtop="10DP"                Android:text="The Tree of CSDN ruins"                android:textsize="20SP"                Android:textstyle="Bold"/>            <textview  android:la Yout_width  = "match_parent"  android:layou T_height  = "wrap_content"  android:layout_ Gravity  = "center"  android:gravity  = "center"  android:paddingtop  = "10DP"  android:text  = "CSD                N the ruins of the tree " android:textsize  =" 20SP " android:textstyle  = "bold" />             <textview  android:la Yout_width  = "match_parent"  android:layou T_height  = "wrap_content"  android:layout_ Gravity  = "center"  android:gravity  = "center"  android:paddingtop  = "10DP"  android:text  = "CSD                N the ruins of the tree " android:textsize  =" 20SP " android:textstyle  = "bold" />             <textview  android:la Yout_width  = "match_parent"  android:layou T_height  = "wrap_content"  android:layout_ Gravity  = "center"  android:gravity  = "center"  android:paddingtop  = "10DP"  android:text  = "CSD                N the ruins of the tree " android:textsize  =" 20SP " android:textstyle  = "bold" />             <textview  android:la Yout_width  = "match_parent"  android:layou T_height  = "wrap_content"  android:layout_ Gravity  = "center"  android:gravity  = "center"  android:paddingtop  = "10DP"  android:text  = "CSD                N the ruins of the tree " android:textsize  =" 20SP " android:textstyle  = "bold" />             <textview  android:la Yout_width  = "match_parent"  android:layou T_height  = "wrap_content"  android:layout_ Gravity  = "center"  android:gravity  = "center"  android:paddingtop  = "10DP"  android:text  = "CSD                N the ruins of the tree " android:textsize  =" 20SP " android:textstyle  = "bold" />         </android.support.v7.widget.LinearLayoutCompat>

Linearlayoutcompat is actually the linerlayout component, just to be compatible with the lower version, so you must refer to the V7 package below the Linearlayoutcompat. Linearlayoutcompat In addition to the original properties of Linerlayout, there are several properties to achieve the interval line effect.

    1. app:divider= "@drawable/line" sets the color for the divider, where you need to define the shape resource in drawable, otherwise there will be no effect. Look underneath.
    2. app:dividerpadding= "25DP" sets the distance between the left and right margins for the divider line.
    3. App:showdividers= the position shown by the "Middle|beginning|end" divider line, there are four parameter values: middle between each item, the top of the beginning displays the divider line, and the end shows the divider line, none does not display the spacer line.

Note that these three properties need to use the xmlns:app= "Http://schemas.android.com/apk/res-auto" namespace

The resource code for app:divider= "@drawable/line" is as follows:

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">    <solid android:color="@color/material_blue_grey_800" />    <!--需要设置高度,否则不显示-->    <size android:height="1px" /></shape>

Summary: Do you still need to draw the dividing line in the future? is not very happy to see the LINEARLAYOUTCOMPAT components!! Ha ha haha

Listpopupwindow


Popupwindow simple and practical, no more to customize, get to determine the location of Popupwindow, etc., you only need to use Listpopupwindow to meet your simple Popupwindow pop-up box use. Directly on the code:

  Public void Showlistpopup(View view) {String items[] = {"Item1","Item2","Item3","Item4","ITEM5"};FinalListpopupwindow Listpopupwindow =NewListpopupwindow ( This);//Set the adapter for the ListView typeListpopupwindow.setadapter (NewArrayadapter<string> (swiperefreshactivity. ThisAndroid. R.layout.simple_list_item_1, items));//Set listener events for each itemListpopupwindow.setonitemclicklistener (NewAdapterview.onitemclicklistener () {@Override             Public void Onitemclick(adapterview<?> parent, view view,intPositionLongID) {Toast.maketext (swiperefreshactivity. This,"The position is"+ position, Toast.length_short). Show ();//Listpopupwindow.dismiss ();}        });//Set the anchor point of the Listpopupwindow, that is, the position of the popup box is displayed relative to the current parameter view.Listpopupwindow.setanchorview (view);//listpopupwindow distance from the anchor point, which is the position of the relative anchor viewListpopupwindow.sethorizontaloffset ( -); Listpopupwindow.setverticaloffset ( -);//Set the width height of the dialog boxListpopupwindow.setwidth ( -); Listpopupwindow.setheight ( -); Listpopupwindow.setmodal (false);    Listpopupwindow.show (); }

According to the above code, you can do the following things:

    1. Listpopupwindow.setanchorview (view); Set where the popover appears
    2. Listpopupwindow.sethorizontaloffset (100); distance from anchor view Horizontal
    3. Listpopupwindow.setverticaloffset (100); The vertical distance from the anchor point view
    4. Listpopupwindow.setwidth (300); Set the size of the popup box

Don't explain it! The code has comments. Look at your own research and then go to handwriting code, so learning faster.

PopupMenu

Menu Popup, the effect is as follows:

The code is as follows:

 Public void ShowPopupMenu(View view) {The //parameter view sets the position of the current menu display relative to the view component, where the system handlesPopupMenu PopupMenu =NewPopupMenu ( This, view);//Load Menu layoutPopupmenu.getmenuinflater (). Inflate (R.menu.menu_main, Popupmenu.getmenu ());//Set Item Click event in menuPopupmenu.setonmenuitemclicklistener (NewPopupmenu.onmenuitemclicklistener () {@Override             Public Boolean Onmenuitemclick(MenuItem Item) {return false; }        });//Set Popupwindow to disappear click eventPopupmenu.setondismisslistener (NewPopupmenu.ondismisslistener () {@Override             Public void Ondismiss(PopupMenu menu)        {            }        });    Popupmenu.show (); }

Summary: PopupMenu is less customizable compared to Listpopupwindow.

Spinner

Pop-style drop-down category component. You only need to use the new style theme in the XML layout to achieve the above effect

<Spinner                android:id="@+id/spinner"                style="@android:style/Widget.Holo.Light.Spinner"                android:layout_width="wrap_content"                android:layout_height="wrap_content"></Spinner>

Subsequent to the discovery of a useful, beautiful UI component will continue to be added. Let's get here today, back to the north!

"Reprint Please specify Source: http://blog.csdn.net/feiduclear_up/article/details/46619637 csdn Ruins of the tree"

Learning and using new components----the flowers

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.