• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > include的用法例子,以及include+merge的用法例子,includemerge

include的用法例子,以及include+merge的用法例子,includemerge

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了include merge,include的用法,jsp include的用法,php include的用法,html include的用法等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

include的用法例子,以及include+merge的用法例子,includemerge


【include+LinearLayout】的使用例子

AndroidIncludeLayout.java

package com.AndroidIncludeLayout; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.Toast; 

public class AndroidIncludeLayout extends Activity { 
     
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
         
        View subLayout1 = (View)findViewById(R.id.main1); 
        View subLayout2 = (View)findViewById(R.id.main2); 
        Button myButton_main1 = (Button)subLayout1.findViewById(R.id.mybutton); 
        Button myButton_main2 = (Button)subLayout2.findViewById(R.id.mybutton); 
        Button startAnotherActivity = (Button)findViewById(R.id.startanotheractivity); 
         
        startAnotherActivity.setOnClickListener(new Button.OnClickListener(){ 

   @Override 
   public void onClick(View arg0) { 
    // TODO Auto-generated method stub 
    Intent intent = new Intent(); 
             intent.setClass(AndroidIncludeLayout.this, AnotherActivity.class); 
             startActivity(intent); 
     
   }}); 
         
        myButton_main1.setOnClickListener(new Button.OnClickListener(){ 

   @Override 
   public void onClick(View arg0) { 
    // TODO Auto-generated method stub 
    Toast.makeText(AndroidIncludeLayout.this, "Button 1 Pressed", Toast.LENGTH_LONG).show(); 
   }}); 
         
        myButton_main2.setOnClickListener(new Button.OnClickListener(){ 

   @Override 
   public void onClick(View arg0) { 
    // TODO Auto-generated method stub 
    Toast.makeText(AndroidIncludeLayout.this, "Button 2 Pressed", Toast.LENGTH_LONG).show(); 
   }}); 
    } 
} 

 

mail.xml 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" 
    /> 
<include android:id="@+id/main1" layout="@layout/sublayout" /> 
<include android:id="@+id/main2" layout="@layout/sublayout" /> 
<Button 
    android:id="@+id/startanotheractivity" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text=" Start Another Activity " 
    /> 
</LinearLayout> 

sublayout.xml 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#505050" 
    > 
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="SubLayout" 
    /> 
<Button 
android:id="@+id/mybutton" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text=" A Button " 
    /> 
</LinearLayout> 

 

 

 

 

 

 

 

【include+merge】   //与上面的include用法有点不一样

LightActivity.java

/**
 * Copyright(c) 2014-2015 ChinaYong Hotel Media Technology Co.,Ltd.
 * All Rights Reserved.
 * 
 * Filename : LightActivity.java
 * Author : Seldy lipeineng
 * Creation time : 上午10:58:53 - 2015-6-4
 * Description :
 */
package com.hysmarthotel.roomcontrol;

import com.hysmarthotel.util.LogUtil;
import com.hysmarthotel.view.Temperature;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
//灯光控制
public class LightActivity extends Activity {
    public static Temperature temp;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.light);
        temp = (Temperature)findViewById(R.id.temperature_light);  //特殊的地方是,可以直接一步调用merge中的id,不用通过include,再去调用
        log("layout1"+temp);
        init();
    }
    private void init() {
        temp.setTemperature(MainActivity.mTemp+"");
    }
    private void log(String msg) {
        LogUtil.info(this.getClass(), this + ":" + msg,"i");
    }
}

 

light.xml

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg1" >
    <TextView
        android:id="@+id/lightctrl"
        android:layout_x="91.5px"
        android:layout_y="93.0px"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:textSize="42.0px"
        android:textColor="#fff3e3d1"
        android:text="@string/light_ctrl"
        android:drawableLeft="@drawable/ic_light_t"
        android:drawablePadding="6px"/>
    
    <include android:id="@+id/include1" layout="@layout/time_temp"/>    
</AbsoluteLayout>

 

time_temp.xml

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:hyhotel="http://schemas.android.com/apk/res/com.hysmarthotel.roomcontrol" >

<com.hysmarthotel.view.Temperature
android:id="@+id/temperature_light"
android:layout_x="1545.0px"
android:layout_y="109.5px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22.5px"
android:textColor="#fff3e3d1"
hyhotel:prefix="@string/room_temp"
hyhotel:unit="@string/celsius" />
</merge>

 

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • include的用法例子,以及include+merge的用法例子,includemerge

相关文章

  • 2017-05-26Android开发学习——打电话应用,android开发打电话
  • 2017-05-26高通QCOM 8610平台电量计算
  • 2017-05-26提升Android ListView性能的几个技巧
  • 2017-05-26Android横竖屏切换小结,Android屏切换小结
  • 2017-05-26文件处理工具类,通用包文件处理工具
  • 2017-05-26Android下雪动画的实现
  • 2017-05-26Android Studio同时打开多个项目,androidstudio
  • 2017-05-26Android Volley框架的使用(4),androidvolley
  • 2017-05-26android布局--Android fill_parent、wrap_content和match_parent的区别,wrapparent
  • 2017-05-26Android 手机卫士--md5加密过程,android--md5

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 安卓--selector简单使用,安卓--selector
    • Android动态加载Dex机制解析
    • Android 配置文件(activity)元素
    • 转载 Android 多线程处理之多线程用法大集合,android大集合
    • Android游戏开发之游戏帧动画的播放与处理,android游戏开发
    • Android如何http获取数据库数据
    • 依赖ConstraintLayout报错,Could not find *****,Failed to resolve:*****,constraintlayout
    • 安卓第十二天笔记-广播,安卓第十二天广播
    • 我的Android进阶之旅------)Java文件大小转换工具类 (B,KB,MB,GB,TB,PB之间的大小转换)
    • Android开发学习—— Broadcast广播接收者,androidbroadcast

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有