Android uses shape to make drawable footage

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="color:rgb(51,51,51);font-family:‘Microsoft Yahei‘, arial, helvetica, sans-serif;line-height:28px;text-indent:14px;background-color:rgb(255,255,255);"><span style="color:rgb(51,51,51);font-family:‘宋体‘, SimSun;line-height:28px;text-indent:14px;background-color:rgb(255,255,255);">Android development, The resource file will have a large number of picture material files, which will increase the size of the app, and sometimes in the face of restrictions on the size of the app, it is necessary to consider compressing the image as much as possible or reduce the number of pictures in the resource file, then reduce the resource material files, How can we meet the rich requirements of the application for graphics? We can use shape to draw, there are many Advantages. To meet our requirements, here are some of the materials I have organized:</span></span></p></p><p><p><span style="color:rgb(51,51,51);font-family:‘宋体‘, SimSun;line-height:28px;text-indent:14px;background-color:rgb(255,255,255);">First look at the final effect:</span></p></p><p style="text-align:left;"><p style="text-align:left;">650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6F/76/wKioL1WdXJiQKM60AAL3Bl7pvsE682.jpg "title=" 1.png " alt= "wkiol1wdxjiqkm60aal3bl7pvse682.jpg"/></p></p><p style="text-align:left;"><p style="text-align:left;"><br></p></p><p style="text-align:left;"><p style="text-align:left;"> <strong> </strong></p></p><pre class="brush:xml;toolbar:false"><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"      Android:layout_width= "match_parent"     android:layout_height= "match_parent"      android:orientation= "vertical"     android:padding= "10dp"  >     <textview        android:layout_width= "wrap_content"         android:layout_height= "wrap_content"          android:layout_marginbottom= "20dp"          android:background= "@drawable/s1"         android:padding= "10dp"          android:text= "@string/s1"          android:textcolor= "#fff"         android:textsize= "16sp"  / >    <Textview        android:layout_width= "wrap_content"          android:layout_height= "wrap_content"          android:layout_marginbottom= "20dp"         android:background= "@ Drawable/s2 "        android:padding=" 10DP "         android:text= "@string/s2"         android: textcolor= "#ff9800"         android:textsize= "16sp"  />     <imagebutton        android:layout_width= "50dp"         android:layout_height= "50dp"          android:layout_marginbottom= "20dp"         android: background= "@drawable/s3" &NBSP;&NBsp;      android:padding= "10dp"          Android:scaletype= "fitxy"         android:src= "@drawable/ic_launcher"  />    <button        android:layout_ Width= "wrap_content"         android:layout_height= "wrap_content"          android:layout_marginbottom= "20dp"          android:background= "@drawable/s4"         android: padding= "5dp"         android:text= "@string/s4"          android:textcolor= "#fff"         android: Textsize= "16sp"  />    <Button         Android:layout_width= "wrap_conTent "        android:layout_height=" wrap_content "         android:layout_marginbottom= "20dp"          android:background= "@drawable/s5"         android:padding= "5dp"         android:text= "@string/s5"          android:textcolor= "#00bcd4"         android:textsize= "16sp"  />    <button        android:layout_ Width= "wrap_content"         android:layout_height= "wrap_content"          android:layout_marginbottom= "20dp"          android:background= "@drawable/s6"         android: padding= "5dp"         android:text= "@string/s6"          android:textcolor= "#fff"         android:textsize= "16sp"  />< /linearlayout></pre><p style="text-align:left;"><p style="text-align:left;"><span style="background-color:rgb(255,255,255);color:rgb(51,51,51);font-family:‘Microsoft Yahei‘, arial, helvetica, sans-serif;line-height:28px;text-indent:14px;"></span><strong>2. Shape file</strong><br></p></p><p style="text-align:left;"><p style="text-align:left;"><strong>1) S1.xml</strong></p></p><pre class="brush:xml;toolbar:false"><pre class="brush:xml;toolbar:false"><?xml version= "1.0" encoding= "utf-8"? ><shape xmlns:android= "http://schemas.android.com/apk/res/android" > <solid android:color= "#23C7B2"/> <corners android:radius= "8dp"/></shape></pre></pre><p style="text-align:left;"><p style="text-align:left;"><strong style="white-space:normal;">2) S2.xml</strong> <span style="background-color:rgb(255,255,255);color:rgb(51,51,51);font-family:‘Microsoft Yahei‘, arial, helvetica, sans-serif;line-height:28px;text-indent:14px;">  </span></p></p><pre class="brush:xml;toolbar:false"><pre class="brush:xml;toolbar:false"><?xml version= "1.0" encoding= "utf-8"? ><shape xmlns:android= "http://schemas.android.com/apk/res/android" > <solid android:color= "#00000000"/> <corners android:radius= "8dp"/> <stroke android:width= "1 DP "android:color=" #ff9800 "/></shape></pre></pre><p><p><strong>3) S3.xml</strong><br></p></p><pre class="brush:xml;toolbar:false"><pre class="brush:xml;toolbar:false"><selector xmlns:android= "http://schemas.android.com/apk/res/android" > <item android:state_pressed= "true"  > <shape android:shape= "oval" > <solid android:color= "#42A0DB"/> </shape> </item> <item android:state_focused= "true" > <shape android:shape= "oval" > <solid android:color= "#42A0DB"/&G    T </shape> </item> <item> <shape android:shape= "oval" > <solid android:color= "#42A0DB"/ > </shape> </item></selector></pre></pre><p><p><strong style="white-space:normal;">4) S4.xml</strong></p></p><pre class="brush:xml;toolbar:false"><selector xmlns:android= "http://schemas.android.com/apk/res/android" >  <item  android:state_pressed= "true" >    <shape>      < solid android:color= "#7F79B5"  />      <corners android: radius= "8dp"  />    </shape>  </item>  <item  android:state_focused= "true" >    <shape>       <solid android:color= "#7F79B5"  />      <corners  android:radius= "8dp"  />    </shape>  </item>  < Item>    <shape>      <solid android:color= "#7F79B8"  />      <corners android:radius= "8dp"  />     </shape&gT;  </item></selector> </pre><p><p> <strong style="white-space:normal;"> </strong> <strong style="white-space:normal;">   5) s5.xml </strong></p></p><pre class="brush:xml;toolbar:false"><selector xmlns:android= "http://schemas.android.com/apk/res/android" >  <item  android:state_pressed= "true" >    <shape>      < solid android:color= "#e3e3e3"  />      <corners android: radius= "8dp"  />      <stroke android:width= "1dp"  android: color= "#00bcd4"  />    </shape>  </item>  <item  android:state_focused= "true" >    <shape>       <solid android:color= "#e3e3e3"  />      <corners  android:radius= "8dp"  />      <stroke android:width= "1dp"   android:color= "#00bcd4"  />    </shape>  </item>   <item>    <shape>      <solid android:color= "#00000000"  />       <corners android:radius= "8dp"  />       <stroke android:width= "1dp"  android:color= "#00bcd4"  />    </ Shape>  </item></selector></pre><p><p> <strong style="white-space:normal;"> </strong> <strong style="white-space:normal;">   6) s6.xml </strong></p></p><pre class="brush:xml;toolbar:false"><?xml version= "1.0"  encoding= "utf-8"? ><selector xmlns:android= "http// Schemas.android.com/apk/res/android " >     <item android:state_ pressed= "true" >    <layer-list>      <item  android:top= "3dp" >        <shape>           <solid android:color= "#00bcd4"  />           <corners android:radius= "8dp"  />         </shape>      </item>     </layer-list>  </item>  <item android:state_focused= "true" >     <layer-list>      <item android:top= "3dp" >       &Nbsp;<shape>          <solid android:color= "# 00BCD4 " />          <corners android:radius= "8dp"  />        </shape>       </item>    </layer-list>  </item>  <item >    <layer-list>      <item>         <shape>           <solid android:color= "#dddddd"  />           <corners android:radius= "8dp"/>        </shape>       </item>      <item android:bottom= " 3DP "&GT;&NBSP;&NBSP;&NBsp;     <shape>          < solid android:color= "#00bcd4"  />          < corners android:radius= "8dp"/>        </shape>       </item>    </layer-list>  </item ></selector></pre><p><p><strong style="white-space:normal;"></strong><strong>3, String.xml</strong><br></p></p><pre class="brush:xml;toolbar:false"><pre class="brush:xml;toolbar:false"><?xml version= "1.0" encoding= "utf-8"?><resources> <string name= "app_name" >shape make drawable footage </ string> <string name= "action_settings" >Settings</string> <string name= "hello_world" >hello worl d!</string> <string name= "s1" > I am the first line </string> <string name= "s2" > I am the second line </string> <s Tring name= "s3" > I'm The third line </string> <string name= "s4" > I'm Line Fourth </string> <string name= "s5" > I'm Fifth Line & lt;/string> <string name= "s6" > I am sixth line </string></resources></pre></pre><p><p><strong>4. Main Interface Activity code</strong></p></p><pre class="brush:java;toolbar:false"><pre class="brush:java;toolbar:false">Package Com.sunny.shape;import Android.os.bundle;import Android.app.activity;import android.view.menu;import Android.view.window;public class Mainactivity extends Activity {@Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); requestwindowfeature (window.feature_no_title); Setcontentview (r.layout.activity_main);}}</pre></pre><p><p>The above is the use of shape to make drawable material, the code is very detailed, do not stick to the source, follow the above steps can make the final effect, you can also make your favorite style, Welcome to learn to Exchange ~</p></p><p><p>This article is from the "sunnygeek technology blog" blog, Please be sure to keep this source http://sunnygeek.blog.51cto.com/9485654/1672463</p></p><p><p>Android uses shape to make drawable footage</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.