复合组件

今天在看到了一个国外关于compound

view 的博客


下图:



可以用framelayout实现


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView  
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
    
        android:scaleType="center"
        android:src="@drawable/golden_gate" />
    
    <TextView
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dip"
        android:layout_gravity="center_horizontal|bottom"

        android:padding="12dip"
        
        android:background="#AA000000"
        android:textColor="#ffffffff"
        
        android:text="Golden Gate" />

</FrameLayout>







还可以用<merge></merge>标签实现


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

    <ImageView  
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
    
        android:scaleType="center"
        android:src="@drawable/golden_gate" />
    
    <TextView
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dip"
        android:layout_gravity="center_horizontal|bottom"

        android:padding="12dip"
        
        android:background="#AA000000"
        android:textColor="#ffffffff"
        
        android:text="Golden Gate" />

</merge>
用merge标签可以减小控件树的高度,并且更易于管理这些控件


注意:merge标签不能再以linearlayout为根标签的布局中使用



重点来了,一个很好的merge应用举例:


要实现下图的效果可以用merge来实现




<merge
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:okCancelBar="http://schemas.android.com/apk/res/com.example.android.merge">

    <ImageView  
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
    
        android:scaleType="center"
        android:src="@drawable/golden_gate" />
    
    <com.example.android.merge.OkCancelBar
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="bottom"

        android:paddingTop="8dip"
        android:gravity="center_horizontal"
        
        android:background="#AA000000"
        
        okCancelBar:okLabel="Save"
        okCancelBar:cancelLabel="Don't>>> null)> "Ok";
        ((Button)>OkCancelBar的代码很简单,用layoutinflater实现:
public class OkCancelBar extends LinearLayout {
    public OkCancelBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        setOrientation(HORIZONTAL);
        setGravity(Gravity.CENTER);
        setWeightSum(1.0f);
        
        LayoutInflater.from(context).inflate(R.layout.okcancelbar, this, true);
        
        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.OkCancelBar, 0, 0);
        
        String text = array.getString(R.styleable.OkCancelBar_okLabel);
        if (text == null) text = "Ok";
        ((Button) findViewById(R.id.okcancelbar_ok)).setText(text);
        
        text = array.getString(R.styleable.OkCancelBar_cancelLabel);
        if (text == null) text = "Cancel";
        ((Button) findViewById(R.id.okcancelbar_cancel)).setText(text);
        
        array.recycle();
    }
}


最后要吐槽下方某的长城防火墙,看个国外的技术博客还要翻墙,f**ck your ......





 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DSAPI.DLL └─DSAPI ├─QQ用户相关 │ └─在线状态 │ ├─在线 │ ├─未知 │ └─离线 ├─内存资源 │ └─清理一下 ├─加载字体 │ └─加载指定字体文件 ├─图形图像 │ ├─从网址获取图片 │ ├─保护图像 │ │ ├─保护图像 │ │ └─解除保护 │ ├─图像特效 │ │ ├─变形 │ │ │ ├─从中心旋转 │ │ │ ├─从指定点旋转 │ │ │ └─调整大小 │ │ └─色彩 │ │ ├─亮度 │ │ ├─保留通道 │ │ ├─反色 │ │ ├─投影效果 │ │ ├─模糊 │ │ ├─灰度 │ │ ├─色彩通道 │ │ │ ├─粉 │ │ │ ├─红 │ │ │ ├─绿 │ │ │ ├─蓝 │ │ │ ├─青 │ │ │ └─黄 │ │ ├─透明度 │ │ └─黑与白 │ ├─彩色文字图像 │ │ ├─代码文本 │ │ ├─字体 │ │ ├─字符行距 │ │ ├─字符间距 │ │ ├─所有连接数量 │ │ ├─描边颜色 │ │ ├─文字清晰度 │ │ ├─文字颜色 │ │ ├─显示文本 │ │ ├─画布尺寸 │ │ ├─绘制描边 │ │ ├─绘制阴影 │ │ ├─获取指定坐标的链接 │ │ ├─输出图像 │ │ ├─链接 │ │ ├─链接下划线颜色 │ │ └─阴影颜色 │ └─透明窗体 │ ├─显示图像 │ ├─窗体支持鼠标拖动 │ ├─窗体支持鼠标调整尺寸 │ ├─绘制圆角矩形 │ └─绘制圆角矩形_带标题栏 ├─字串提取 │ ├─提取中间文本 │ └─提取所有中间文本 ├─序列化 │ ├─反序列化 │ ├─序列化 │ └─绑定 ├─文件类 │ ├─修改指定文件扩展名为指定打开方式 │ ├─压缩 │ ├─取消文件头 │ ├─添加文件头 │ ├─获取可读性强的字节大小信息 │ ├─解压缩 │ └─追加文件尾 ├─硬件信息 │ ├─硬件列表 │ ├─硬件选择 │ │ ├─主板 │ │ ├─光盘驱动器 │ │ ├─包括鼠标 │ │ ├─声卡 │ │ ├─打印机 │ │ ├─打印机任务 │ │ ├─指针设备 │ │ ├─显卡 │ │ ├─物理内存条 │ │ ├─硬盘序列号 │ │ ├─硬盘驱动器 │ │ ├─网络适配器 │ │ ├─软盘驱动器 │ │ └─键盘 │ └─获取硬件信息 ├─系统信息 │ ├─主显示器屏幕大小 │ ├─主显示器工作区大小 │ ├─使用交流电 │ │ ├─否 │ │ ├─是 │ │ └─未知 │ ├─启用列表框平滑滚动效果 │ ├─启用字体平滑效果 │ ├─启用平滑组合框打开效果 │ ├─启用按钮动画效果 │ ├─启用提示框淡入淡出效果 │ ├─启用标题栏渐变效果 │ ├─启用桌面主题 │ ├─启用窗口还原动画效果 │ ├─启用窗口阴影效果 │ ├─启用自动对齐默认按钮 │ ├─启用菜单淡入淡出效果 │ ├─图标排列单元格高度 │ ├─图标排列格子大小 │ ├─子菜单延迟显示时间 │ ├─屏幕旋转角度 │ ├─工作组 │ ├─已连接交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值