zoukankan      html  css  js  c++  java
  • Android——ViewGroup的一个用法实例(转载)

    找了很久,终于找到了。 

    Xml代码  收藏代码
    1. <?xml version="1.0" encoding="UTF-8" ?>  
    2. <merge  xmlns:android="http://schemas.android.com/apk/res/android"  
    3.     xmlns:okCancelBar="http://schemas.android.com/apk/res/com.example.android.merge">  
    4.     <ImageView  
    5.         android:layout_width="fill_parent"  
    6.         android:layout_height="fill_parent"  
    7.         android:scaleType="center"  
    8.         android:src="@drawable/golden_gate"  
    9.   
    10.     />  
    11.     <com.example.android.merge.OkCancelBar  
    12.   
    13.         android:layout_width="fill_parent"  
    14.         android:layout_height="wrap_content"  
    15.         android:layout_gravity="bottom"  
    16.         android:paddingTop="8dip"  
    17.         android:gravity="center_horizontal"  
    18.         android:background="#AA000000"  
    19.         okCancelBar:okLabel="Save"  
    20.         okCancelBar:cancelLabel="Don't save"   
    21.     />  
    22. </merge>  

     com.example.android.merge.OkCancelBar是一个自定义的GROUP

    Java代码  收藏代码
    1. public class OkCancelBar extends LinearLayout{  
    2.   
    3.     public OkCancelBar(Context context,AttributeSet attrs){  
    4.   
    5.         super(context, attrs);  
    6.   
    7.         setOrientation(HORIZONTAL);  
    8.   
    9.         setGravity(Gravity.CENTER);  
    10.   
    11.         setWeightSum(1.0f);  
    12.   
    13.         LayoutInflater.from(context).inflate(R.layout.okcancelbar,this,true);  
    14.   
    15.   
    16.         TypedArray array= context.obtainStyledAttributes(attrs, R.styleable.OkCancelBar,0,0);  
    17.   
    18.   
    19.         String text= array.getString(R.styleable.OkCancelBar_okLabel);  
    20.   
    21.         if(text==null) text="Ok";  
    22.   
    23.         ((Button) findViewById(R.id.okcancelbar_ok)).setText(text);  
    24.             text= array.getString(R.styleable.OkCancelBar_cancelLabel);  
    25.   
    26.         if(text==null) text="Cancel";         
    27.   
    28.         ((Button) findViewById(R.id.okcancelbar_cancel)).setText(text);  
    29.   
    30.   
    31.         array.recycle();  
    32.   
    33.   
    34.     }  
    35. }  

     LayoutInflater.from(context).inflate(R.layout.okcancelbar,this,true); 

    直接从XML中得到一个VIEW加入到当前GROUP中 

    okcancelbar.xml: 

    Xml代码  收藏代码
    1. <merge xmlns:android="http://schemas.android.com/apk/res/android">  
    2.   
    3. <include layout="@layout/okcancelbar_button"  android:id="@+id/okcancelbar_ok"/>  
    4. <include  layout="@layout/okcancelbar_button" android:id="@+id/okcancelbar_cancel"/>  
    5.   
    6. </merge>  
  • 相关阅读:
    java.lang.NoClassDefFoundError: org/activiti/validation/ProcessValidator
    java.lang.NoClassDefFoundError: org/activiti/image/ProcessDiagramGenerator
    14.10.1 InnoDB Disk I/O
    shiro权限验证标签
    14.9.4 COMPACT and REDUNDANT Row Formats
    Spring整合Shiro做权限控制模块详细案例分析
    14.9.2 Specifying the Row Format for a Table 指定 表的行格式
    全虚拟化与半虚拟化的实现方式
    全虚拟化与半虚拟化的实现方式
    查询方式的一般使用2
  • 原文地址:https://www.cnblogs.com/xiaochao1234/p/3997670.html
Copyright © 2011-2022 走看看