Android Implementation dialog Fillet function

Source: Internet
Author: User
<span id="Label3"></p><p><p>Android <span style="font-family:宋体">implements Custom</span> <span style="font-family:Times New Roman">dialog</span> <span style="font-family:宋体">fillet features</span></p></p><p><p></p></p><p><p>Just contact the Company's <span style="font-family:Times New Roman">Android</span> <span style="font-family:宋体">project, The customer drew the interface, the requirements are as Follows:</span></p></p><p><p><span style="font-family:宋体"><br></span></p></p><p><p></p></p><p><p><span style="color:#ff0000"><strong>pop-up window is to four rounded corners, and the title bar color and below the same, but also to be separated by the Blue Line</strong></span> , through the online various baidu, the solution is basically to <span style="font-family:宋体">create a shape under</span> the <span style="font-family:Times New Roman">/drawable</span> folder <span style="color:rgb(0,0,128); background:rgb(228,228,255)"> </span>file, which controls the Control. <span style="color:#3333ff">(note here that the <span style="font-family:Times New Roman">shape</span> <span style="font-family:宋体">file should be placed</span> under the <span style="font-family:Times New Roman">drawable</span> <span style="font-family:宋体">folder, As for why it should be placed here, as well as the various element usages under the root element, please refer to the Predecessor's blog:</span> http://blog.csdn.net/lonelyroamer/article/details/8254592 <span style="font-family:宋体">explained in Great detail). </span></span></p></p><p><p></p></p><p><p>The key point is that <span style="font-family:Times New Roman"><strong><span style="color:#cc0000">shape</span></strong></span> <span style="font-family:宋体"> <strong><span style="color:#cc0000">provides a number of elements to control the color, rounded corners (the radius size can be controlled in four Directions)</span></strong>. Since we need to use the round corner of the pop-up window, we have to use the following element</span> <span style="font-family:Times New Roman">Corners</span> <span style="font-family:宋体">to control, the project directory is:</span><span style="font-family:Times New Roman">F:\PopwindowOnLeft1\app\src\main\res\ Drawable-mdpi\shapeyuanjiao3.xml</span><span style="font-family:宋体">:</span></p></p><p><?xml version= "1.0" encoding= "UTF-8"?><br><shape xmlns:android= "http://schemas.android.com/apk/res/android"<br>Android:shape= "rectangle" ><br><br><!--<span style="font-family:宋体"><span style="font-family:宋体">the color of the fill</span></span><span style="font-family:Times New Roman"><span style="font-family:Times New Roman"></span> -</span><br><solid android:color= "#0000FF"/><br><strong><strong> <span style="color:#ff0000"><!-- <span style="font-family:宋体">Set the Four corners of the button arc-- </span> <span style="font-family:Times New Roman"></span><br><!--android:radius <span style="font-family:宋体">arc radius-- </span> <span style="font-family:Times New Roman"></span><br><corners android:topleftradius= "@dimen/roundedamplitude" android:toprightradius= "@dimen/roundedamplitude"/ ></span> </strong></strong><br><br><gradient<br>Android:angle= "270"<br>Android:centercolor= "#0000FF"<br>Android:endcolor= "#0000FF"<br>Android:startcolor= "#0000FF"/><br><br><br></shape></p><p><p>The above code in the <strong> <span style="font-family:Times New Roman">corner</span> <span style="font-family:宋体">can be set above and below the two corners, not set the default is the radius of</span> <span style="font-family:Times New Roman">0</span></strong><span style="font-family:宋体">, which we can test on the MACHINE. </span></p></p><p><p>After setting the fillet dimension, it is necessary to use in the layout file, it is very simple to use, through <span style="font-family:Times New Roman">layout</span><span style="font-family:宋体">,</span><span style="font-family:Times New Roman">view</span><span style="font-family:宋体">,</span><span style="font-family:Times New Roman">textview</span> , <span style="font-family:宋体">etc.</span> <span style="color:#cc0000"><strong>android:background= The "@drawable/shapeyuanjiao3" property</strong></span> , set the dimensions, rounded corners (you can customize which corner to display separately for rounded corners).</p></p><p><p>well, go into the actual need to come, in order to show the initial layout, I used a relative layout, the file is as Follows:</p></p><p><?xml version= "1.0" encoding= "utf-8"?><br><br><relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"<br>Android:layout_width= "match_parent"<br>android:layout_height= "match_parent" ><br><com.pop.main.clipimageview android:layout_width= "match_parent" android:layout_height= "match_parent"<br>Android:id= "@+id/front_image"/><br><br><imageview android:layout_width= "match_parent" android:layout_height= "match_parent"<br>Android:background= "#33000000"/><br><br><strong><span style="color:#cc0000"><span style="color:#cc0000"><linearlayout android:layout_width= "match_parent" android:layout_height= "wrap_content</span> "</span><br><span style="color:#cc0000"><span style="color:#cc0000">android:layout_marginleft= "60dp"</span></span><br><span style="color:#cc0000"><span style="color:#cc0000">android:layout_marginright= "60dp"</span></span><br><span style="color:#cc0000"><span style="color:#cc0000">android:orientation= "vertical" android:layout_centerinparent= "true"</span></span><br><span style="color:#cc0000"><span style="color:#cc0000">        </span></span><span style="color:#3333ff"><span style="color:#3333ff">android:background= "@drawable/shapeyuanjiao" ></span></span><br><span style="color:#cc0000"><span style="color:#cc0000"><textview android:layout_width= "match_parent" android:layout_height= "30dip</span> "</span><br><span style="color:#cc0000"><span style="color:#cc0000">           </span></span><span style="color:#3333ff"><span style="color:#3333ff">android:background= "@drawable/shapeyuanjiao3"</span></span><br><span style="color:#cc0000"><span style="color:#cc0000">android:text= "</span></span><span style="color:rgb(204,0,0); font-family:宋体"><span style="color:rgb(204,0,0); font-family:宋体">Guaranteed Gold</span> status</span><span style="color:rgb(204,0,0); font-family:‘Times New Roman‘"><span style="color:rgb(204,0,0); font-family:‘Times New Roman‘">"</span></span><br><span style="color:#cc0000"><span style="color:#cc0000">android:gravity= "center"</span></span><br><span style="color:#cc0000"><span style="color:#cc0000">android:textcolor= "@color/white"/></span></span><br><span style="color:#cc0000"><span style="color:#cc0000">        </span></span><span style="color:#3333ff"><span style="color:#3333ff"><view android:layout_height= "1dip"<br>Android:layout_width= "match_parent"<br>android:background= "@color/blue"/><!--display the divider line--</span></span></strong><br><textview android:layout_width= "match_parent"<br>android:layout_height= "30dip"<br><br>Android:text= "<span style="font-family:宋体"><span style="font-family:宋体">No. Mega</span></span><span style="font-family:Times New Roman"><span style="font-family:Times New Roman">09102 "</span></span><br>Android:textcolor= "@color/black"/><br><br><textview android:layout_width= "match_parent" android:layout_height= "30dip"<br><br>Android:text= "<span style="font-family:宋体"><span style="font-family:宋体">Floating Profit</span></span><span style="font-family:Times New Roman"><span style="font-family:Times New Roman">"</span></span><br>Android:textcolor= "@color/black"/><br><br></LinearLayout><br><br><br></RelativeLayout></p><p><p></p></p><p>Please note<span style="color:#3333ff"><strong><span style="font-family:Times New Roman"><span style="font-family:Times New Roman"><textview android:layout_width= "match_parent" android:layout_height= "30dip</span> "</span><br>Android:background= "@drawable/shapeyuanjiao3"<br>Android:text= "<span style="font-family:宋体"><span style="font-family:宋体">Guaranteed Gold</span> status</span><span style="font-family:Times New Roman"><span style="font-family:Times New Roman">"</span></span><br>android:gravity= "center"<br>Android:textcolor= "@color/white"/><br><view android:layout_height= "1dip"<br>Android:layout_width= "match_parent"<br>Android:background= "@color/blue"/></strong></span></p><p><p>This code is the key,<span style="color:#3333ff"><strong><em><span style="font-family:Times New Roman">textview</span> <span style="font-family:宋体">is</span> <span style="font-family:Times New Roman"></span> <span style="font-family:宋体">The dialog table header, set to Blue Separately. The overall</span> <span style="font-family:Times New Roman">dialog</span> <span style="font-family:宋体">window needs to be set to gray, so a different</span> <span style="font-family:Times New Roman">shape</span> </em></strong></span> file is required <span style="font-family:宋体"> <span style="color:#3333ff"><strong><em>, and two files are only slightly different on the number and color of the rounded corners. You can see the effect by making a slight change</em></strong></span> . The following is</span> <span style="font-family:Times New Roman"></span> <span style="font-family:宋体">The setup of</span> the entire dialog:</p></p><p><p><linearlayout android:layout_width= "match_parent" android:layout_height= "wrap_content"<br>android:layout_marginleft= "60dp"<br>android:layout_marginright= "60dp"<br>android:orientation= "vertical" android:layout_centerinparent= "true"<br>android:background= "@drawable/shapeyuanjiao" ></p></p><p><p>The results of the actual operation are as follows <span style="font-family:Times New Roman">:</span></p></p><p><p></p></p><p><p>The interface is a bit ugly, mo. In fact, in the process of doing, go a lot of detours, I listed it, to meet the same problem of people to provide some experience, the technology is not enough places please criticize correct.</p></p><p><p>Detour One:</p></p><p><p>I got <span style="color:#cc0000"> <strong>another one from the Internet. setting the <span style="font-family:Times New Roman">dialog</span> <span style="font-family:宋体">to rounded corners is also set by</span> the <span style="font-family:Times New Roman">shape</span> <span style="font-family:宋体">file, But the method is a little tortuous, by giving the entire</span> <span style="font-family:Times New Roman">dialog </span>The <span style="font-family:宋体">outer layer also adds a rounded corner, where the entire window looks like it's being wrapped together,</span>and the<span style="font-family:Times New Roman">shape</span> <span style="font-family:宋体">file is as Follows:</span> </strong></span></p></p><p><?xml version= "1.0" encoding= "utf-8"?><br><shape xmlns:android= "http://schemas.android.com/apk/res/android" ><br><solid android:color= "#0033FF"/><br>//<span style="font-family:宋体"><span style="font-family:宋体">Set Margins</span></span><span style="font-family:Times New Roman"><span style="font-family:Times New Roman">,</span></span><span style="font-family:宋体"><span style="font-family:宋体">achieve rounded corners function</span></span><br><padding<br>Android:bottom= "4dp"<br>android:left= "4dp"<br>android:right= "4dp"<br>android:top= "4dp"/><br><br>//<span style="font-family:宋体"><span style="font-family:宋体">control boundary Line color and stroke size</span></span><br><stroke<br>Android:width= "1dp"<br>Android:color= "#CdCdCd"/><br><br>//<span style="font-family:宋体"><span style="font-family:宋体">control the color gradient of the interface (you can't use This)</span></span><br><gradient<br>Android:startcolor= "#E9E9E9"<br>Android:endcolor= "#FFFFFF"<br>Android:type= "linear"<br>Android:angle= "/>"<br><br>//<span style="font-family:宋体"><span style="font-family:宋体">controlling the size of rounded corners</span></span><br><corners android:radius= "10dp"/><br><br></shape></p><p><p>Note this code:</p></p><p><p><span style="font-family:宋体">set the Margins</span> <span style="font-family:Times New Roman">to</span> <span style="font-family:宋体">achieve rounded corners</span><br><padding<br>Android:bottom= "4dp"<br>android:left= "4dp"<br>android:right= "4dp"<br>android:top= "4dp"/> <span style="font-family:宋体">This way a bit less in line with the requirements of customers, have the need for friends to refer to, I run the results are as follows:</span></p></p><p><p><span style="font-family:宋体"><br></span></p></p><p><p></p></p><p><p>Detour <span style="font-family:Times New Roman">2</span><span style="font-family:宋体">:</span></p></p><p>In the layout file, I thought of it at first, since the color of the title is not the same as the following, I use<span style="color:rgb(102,14,122)"><span style="color:rgb(102,14,122)">Android</span></span><span style="color:rgb(0,0,255)"><span style="color:rgb(0,0,255)">: background=</span></span><span style="color:rgb(0,128,0)"><span style="color:rgb(0,128,0)">"@</span></span><span style="color:rgb(0,128,0)"><span style="color:rgb(0,128,0)">Color/blue</span></span><span style="color:rgb(0,128,0)"><span style="color:rgb(0,128,0)">"</span></span><span style="color:rgb(0,128,0)"><span style="color:rgb (0,128,0)"> This setting, then the peripheral <span style="font-family:consolas">linelayout </span> <span style=" font-family: Arial "> set </span> <span style=" font-family:consolas ">android:background=" @drawable/shapeyuanjiao3 " </span> <span style="font-family: song body"> but found that after running, there is no fillet effect, Consulting the company colleagues only found, although set up the entire </span> <span style="font-family:consolas">layout </span> <span style="font-family: The song body" and the < span> <span style="font-family:consolas">shape </span> <span style="font-family: arial"> rounded effect, but for each row of </span> <span style="font-family:consolas">imageview </span> <span style="font-family: song body"> set </span> <span style="font-family:consolas">background </span> <span style="font-family: Song body" , it will cover the outer style, resulting in display, solution is each individual < span> <span style="font-family:consolas">imageview </span> <span style="font-family: arial"> Do not set the color, give the title blue separately with another </span> <span style="font-family:consolas">shape </span> <span style="font-family: Song body"> set to blue on it. </span></span></span></span></span></p><p><p><span style="color:rgb(0,128,0)">Some places are not very clear, you can ask me, this small <span style="font-family:Consolas">demo</span> <span style="font-family:宋体">can be downloaded from here, Welcome to Download. </span></span></p></p><p><p>http://download.csdn.net/detail/omayyouhappy/8888251 is free and can give newbies some advice. And this code or the background image of the function of the blur, in particular, can refer to my next blog: about the Android background image of the blurred solution?<br></p></p><p><p></p></p><p><p></p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>Android Implementation dialog Fillet function</p></p></span>

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.