Android中的XML文件的作用介绍

来源:互联网 发布:q语言 知乎 编辑:程序博客网 时间:2024/05/18 21:39
 

WindowManager 用法  添加View,然后移除View

WindowManager                            wm=(WindowManager)ChangeStatus.this.getSystemService(Context.WINDOW_SERVICE);

LayoutInflater inflater=LayoutInflater.from(ChangeStatus.this);

final View view=inflater.inflate(R.layout.infor_text, null);

WindowManager.LayoutParams mParams = new WindowManager.LayoutParams();

wm.addView(view,mParams);  //添加

view.findViewById(R.id.btn_infor).setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

wm.removeView(view);   //移除

}

});

当RelativeLayout 的addStatesFromChildren属性设置为true,点击RelativeLayout 上的任意控件,RelativeLayout 都呈现被点击的效果显示

例如:

<RelativeLayout android:gravity="center_vertical" android:id="@+id/phoinix_settings_notification"

    android:layout_alignParentTop="true" android:layout_width="fill_parent" android:addStatesFromChildren="true"

    android:layout_height="wrap_content" android:background="@xml/phoinix_settings_click_bottom_style">

   <TextView android:id="@+id/phoinix_settings_notificationLabel"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:text="@string/phoinix_settings_notificationLabel" style="@style/Label" />

    <ImageButton android:id="@+id/phoinix_settings_notificationImage"

android:layout_centerVertical="true"

android:layout_alignParentRight="true" android:layout_marginRight="2dp"

android:background="@xml/phoinix_profile_mainmenu_style" android:layout_width="wrap_content"

android:layout_height="wrap_content" />

   </RelativeLayout>

Android XML 各种类型文件写法:

Arrays.xml     定义数组

<resources>

<string-array name="proxy_types">

<item>HTTP</item>

<item>SOCKS4</item>

<item>SOCKS5</item>

</string-array>

</resources>

Colors.xml

<resources>

<color name="blue_sky">#A0C8FF</color>

<color name="vert_manu">#CCFF00</color>

<color name="black">#000000</color>

<color name="white">#FFFFFF</color>

<color name="red">#FF0000</color>

<color name="link_color">#FF0066CC</color>

<color name="simiple_button_color">#FFF</color>

<color name="blue">#0000FF</color>

<color name="grey">#FFCBD2D8</color>

</resources>

在res / values目录内的任何xml档,使用<dimen>做为大小尺寸标签.

Dimens.xml   定义尺寸值

<?xml version="1.0" encoding="utf-8"?>

<resources>

<dimen name="bottom_tab_font_size">12dp</dimen>

<dimen name="bottom_tab_padding_up">5dp</dimen>

<dimen name="bottom_tab_padding_drawable">8dp</dimen>

</resources>

Drawables.xml

<resources>

    <item type="drawable" name="shader1">#7f7f7f7f</item>

    <item type="drawable" name="highlight">#cf7f7f7f</item>

    <item type="drawable" name="barbg">#ef0a4267</item>

    <item type="drawable" name="trans">#00000000</item>

    <item type="drawable" name="chatdivider">#ffd6dadc</item>

</resources>

Strings.xml

<resources>

<!-- Generic terms -->

<string name="app_name">Beem</string>

<string name="OkButton">Ok</string>

<string name="ClearButton">Clear</string>

<string name="CancelButton">Cancel</string>

<string name="AcceptButton">Authorize</string>

<string name="RefuseButton">Deny</string>

</resources>

Styles.xml

<resources>

<style name="Label">

<item name="android:textSize">18sp</item>

<item name="android:textStyle">bold</item>

    <item name="android:typeface">sans</item> 

<!--  <item name="android:capitalize">characters</item>  -->

<item name="android:textColor">#000000</item> <!-- #FFFFFF -->

    <item name="android:focusable">false</item>  

<item name="android:padding">12dip</item>

</style>

</resources>

phoinix_popumenu_style.xml     selector选择

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_focused="true" android:state_pressed="true"

       android:drawable="@drawable/phoinix_pushmail_btn_selected" />

    <item android:state_focused="false" android:state_pressed="true"

       android:drawable="@drawable/phoinix_pushmail_btn_selected" />

    <item android:state_focused="true"

       android:drawable="@drawable/phoinix_small_selected"/>

</selector>

Menu

<menu xmlns:android="http://schemas.android.com/apk/res/android">

<group>

<item android:id="@+id/chat_menu_contacts_list" android:visible="true"

android:title="@string/chat_menu_contacts_list" android:icon="@drawable/ic_menu_friendslist" />

<item android:id="@+id/chat_menu_change_chat" android:visible="true"

android:title="@string/chat_menu_change_chat" android:icon="@drawable/ic_menu_chat_dashboard" />

</group>

<item android:id="@+id/chat_menu_close_chat" android:visible="true"

android:title="@string/chat_menu_close_chat" android:icon="@drawable/ic_menu_end_conversation" />

</menu>

<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@+id/contact_list_context_menu_chat_item"

android:title="@string/CDChat">

<menu>

</menu>

</item>

<item android:id="@+id/contact_list_context_menu_call_item"

android:title="@string/CDCall" android:visible="false" />

<item android:id="@+id/contact_list_context_menu_user_info"

android:title="@string/CDInfos">

<menu>

<item android:id="@+id/contact_list_context_menu_userinfo_alias"

android:title="@string/userinfo_label_alias" />

<item android:id="@+id/contact_list_context_menu_userinfo_group"

android:title="@string/userinfo_label_chg_group" />

<item android:id="@+id/contact_list_context_menu_userinfo_subscription"

android:title="@string/userinfo_label_re_subscription" />

<item android:id="@+id/contact_list_context_menu_userinfo_block"

android:title="@string/userinfo_label_block" android:visible="false" />

<item android:id="@+id/contact_list_context_menu_userinfo_delete"

android:title="@string/userinfo_label_delete" />

</menu>

</item>

</menu>

Drawable  white_background.xml  白色圆角矩形做背景

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 

    <solid android:color="#FFFFFF" /> 

    <corners android:topLeftRadius="5px" 

        android:topRightRadius="5px" android:bottomLeftRadius="5px" 

        android:bottomRightRadius="5px"/> 

   <!--   <padding android:left="10dp" android:top="10dp" android:right="10dp" 

        android:bottom="10dp" />  

          <stroke   

            android:dashWidth="2dp"   

            android:dashGap="2dp"  

            android:width="2dp"   

            android:color="#FF00ff00"></stroke>  --> 

   <!--  -->

</shape>

Anim  旋转动画

· <set xmlns:android="http://schemas.android.com/apk/res/android">  

·           

· <rotate   

·         android:interpolator="@android:anim/accelerate_decelerate_interpolator"  

·         android:fromDegrees="0"   

·         android:toDegrees="+360"  

·         android:duration="3000" />  

·           

· <!-- rotate 旋转动画效果  

·        属性:interpolator 指定一个动画的插入器,用来控制动画的速度变化  

·         fromDegrees 属性为动画起始时物件的角度      

·         toDegrees   属性为动画结束时物件旋转的角度,+代表顺时针  

·         duration  属性为动画持续时间,以毫秒为单位  

· -->  

· </set> 

<set xmlns:android="http://schemas.android.com/apk/res/android">

    <rotate android:fromDegrees="0" android:toDegrees="360"

android:pivotX="50%" android:pivotY="50%"

android:duration="5000"

android:repeatMode="restart"

android:repeatCount="infinite" />

</set>

XML中 
alpha 
渐变透明度动画效果 
scale 
渐变尺寸伸缩动画效果 
translate 
画面转换位置移动动画效果 
rotate 
画面转移旋转动画效果 

 <set xmlns:android="http://schemas.android.com/apk/res/android">   

    

     <!--    

         Tween Animation:通过对场景里的对象不断做图像变换(平移、缩放、旋转)产生动画效   

            

         Alpha:渐变透明度动画效果   

         Scale:渐变尺寸伸缩动画效果   

         Translate:画面转换位置移动动画效果   

         Rotate:画面旋转动画效果   

            

         Tween Animation 通用属性[类型]    功能     

             Duration[long]  属性为动画持续时间   时间以毫秒为单位   

             fillAfter [boolean] 当设置为true ,该动画转化在动画结束后被应用   

             fillBefore[boolean] 当设置为true ,该动画转化在动画开始前被应用   

                

             interpolator    指定一个动画的插入器  有一些常见的插入器   

             accelerate_decelerate_interpolator   

             加速-减速 动画插入器   

             accelerate_interpolator   

             加速-动画插入器   

             decelerate_interpolator   

             减速- 动画插入器   

             其他的属于特定的动画效果   

             repeatCount[int]    动画的重复次数    

             RepeatMode[int] 定义重复的行为 1:重新开始  2:plays backward   

             startOffset[long]   动画之间的时间间隔,从上次动画停多少时间开始执行下个动画   

             zAdjustment[int]    定义动画的Z Order的改变 0:保持Z Order不变   

             1:保持在最上层   

             -1:保持在最下层 

      -->   

     <!--   

         透明控制动画    

      -->   

     <alpha   

         android:fromAlpha="0.1"    

         android:toAlpha="1.0"   

         android:duration="3000"   

     />   

            

     <!-- 尺寸伸缩动画效果 scale   

       

         属性:interpolator 指定一个动画的插入器   

    

         有三种动画插入器:   

          accelerate_decelerate_interpolator  加速-减速 动画插入器   

          accelerate_interpolator        加速-动画插入器   

          decelerate_interpolator        减速- 动画插入器   

    

         其他的属于特定的动画效果   

    

             fromXScale 属性为动画起始时 X坐标上的伸缩尺寸       

             toXScale   属性为动画结束时 X坐标上的伸缩尺寸        

    

             fromYScale 属性为动画起始时Y坐标上的伸缩尺寸       

             toYScale   属性为动画结束时Y坐标上的伸缩尺寸       

    

             说明:   

                  以上四种属性值       

                     0.0表示收缩到没有    

                     1.0表示正常无伸缩        

                     值小于1.0表示收缩     

                     值大于1.0表示放大   

                        

             pivotX     属性为动画相对于物件的X坐标的开始位置   

             pivotY     属性为动画相对于物件的Y坐标的开始位置   

             说明:   

                     以上两个属性值 从0%-100%中取值   

                     50%为物件的X或Y方向坐标上的中点位置   

         长整型值:   

             duration  属性为动画持续时间   

             说明:   时间以毫秒为单位   

    

         布尔型值:   

             fillAfter 属性 当设置为true ,该动画转化在动画结束后被应用   

     -->   

     <scale 

         android:interpolator="@android:anim/accelerate_decelerate_interpolator"   

         android:repeatCount="1"   

            

         android:fromXScale="0.5"   

         android:fromYScale="0.5"   

         android:toXScale="1.4"         

         android:toYScale="1.4"   

         android:pivotX="50%"   

         android:pivotY="50%"   

         android:fillAfter="false"   

         android:duration="3000"   

            

     />   

     <!--    

         画面转换位置移动动画效果 translate   

        

         fromXDelta toXDelta 为动画、结束起始时 X坐标上的位置      

         fromYDelta toYDelta 为动画、结束起始时 Y坐标上的位置   

      -->   

  

     <translate   

         android:repeatCount="2"   

         android:fromXDelta="-30"   

         android:fromYDelta="-30"   

         android:toXDelta="-80"         

         android:toYDelta="200"   

         android:duration="3000"   

     />   

     <!--    

         画面转移旋转动画效果 rotate   

            

         fromDegrees 为动画起始时物件的角度 说明   

             当角度为负数——表示逆时针旋转   

             当角度为正数——表示顺时针旋转   

             (负数from——to正数:顺时针旋转)   

             (负数from——to负数:逆时针旋转)   

             (正数from——to正数:顺时针旋转)   

             (正数from——to负数:逆时针旋转)   

             toDegrees   属性为动画结束时物件旋转的角度 可以大于360度   

         pivotX   

         pivotY  为动画相对于物件的X、Y坐标的开始位  说明:以上两个属性值 从0%-100%中取值   

         50%为物件的X或Y方向坐标上的中点位置   

      -->   

     <rotate   

         android:interpolator="@android:anim/accelerate_interpolator"   

         android:repeatCount="2"   

         android:fromDegrees="0"   

         android:toDegrees="+270"   

         android:pivotX="50%"   

         android:pivotY="50%"   

         android:duration="3000"   

     />   

   

 </set>   

加入动画

 Animation mAnimation ;   

 mAnimation = AnimationUtils.loadAnimation(this, R.anim.anim);   

 TextView text = (TextView)findViewById(R.id.textview00);   

 text.setAnimation(mAnimation);

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 小孩咳喘有痰怎么办 都说我不爱说话怎么办 宝宝突然结巴了怎么办 淘宝客户不理人怎么办 遇到不说话客户怎么办 同学群没人聊怎么办 群里没人说话怎么办 儿童说话声音沙哑怎么办 孩子不和外人说话怎么办 同学退群该怎么办 宝宝睡觉枕头湿怎么办 一个多月的小宝宝便秘怎么办 小宝宝便秘拉屎困难怎么办 一岁小宝宝便秘怎么办 客户不听我说话怎么办 微信上客户不理怎么办 小宝宝母乳不够吃怎么办 小宝宝吃母乳拉肚子怎么办 母乳小宝宝吃奶吃不了怎么办 婴儿感冒吐奶怎么办 小孩感冒吐奶怎么办 小孩吐奶怎么办月子 新生儿一直吐奶怎么办 宝宝50天吐奶厉害怎么办 小儿吐奶厉害怎么办 宝宝一直便秘了怎么办 误建了微信群聊怎么办 新生儿大口吐奶怎么办 宝宝喝了就吐奶怎么办 婴儿顿顿吐奶怎么办 说话着急就结巴怎么办 幼儿舌头长泡怎么办 一着急说话结巴怎么办 幼儿舌头又溃疡怎么办 3儿童说话结巴怎么办 孩子小舌头短怎么办? 6岁讲话不清楚怎么办 三岁宝宝结巴怎么办 新生儿儿有舌苔怎么办 严重口吃的孩子怎么办 口吃越来越严重了怎么办