在开发app的时候,有时候一个布局会反复用到,可以把反复用到的布局单独写一个xml文件,什么时候用到就用includ标签引入xml

下面是我写的反复用到的一个xml,里面有2个button,一个TextView和一个ProgressBar

layout_progress.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="gone" >

<ProgressBar
android:id="@+id/ap_comments_progress"
style="@style/LoadingProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />

<TextView
android:id="@+id/tv_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/loading"
android:textColor="@color/text_color_blue"
android:textSize="16sp" />

  <LinearLayout
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:id="@+id/linear_layout_btn"
  android:visibility="visible"
  android:orientation="vertical">
    <Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/stop_smart_config"
      android:id="@+id/btn_cancel_config"
      android:onClick="cancelConfig"
    />

    <Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/resmart_config"
      android:id="@+id/btn_re_config"
      android:onClick="reConfig"
    />

  </LinearLayout>

</LinearLayout>

在一个MainActivity引入这个布局,在activity_main.xml加入下面的代码:

<include
android:id="@+id/layout_loading"
layout="@layout/layout_progress" />

上面的layout_progress.xml中,设置visibility属性:android:visibility="gone" ,这个布局是隐藏的,我想在点击一个button的时候显示这个布局并隐藏当前布局。activity_main.xml中写一个button:

activity_main.xml

<Button
android:id="@+id/bt_config_router"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:onClick="configToRouter"
android:text="@string/configure_to_route" />

在MainActivity中是这么写的:

private View loadingLayout,bodyLayout;//定义引用布局和当前布局

  loadingLayout = findViewById(R.id.layout_loading);
  bodyLayout = findViewById(R.id.body_layout);

  public void configToRouter(View v){

    loadingLayout.setVisibility(View.VISIBLE);//显示引用布局
    bodyLayout.setVisibility(View.GONE);//隐藏当前布局
}

这样点击按钮,就触发了显示引用布局,隐藏当前布局。

Android中include标签的使用(打开引用布局,隐藏当前布局)的更多相关文章

  1. android中include标签使用详解

    android中include标签是为了便于控件的覆用的一个很好解决方案.   但是也有一些需要注意的地方,下面是本人在项目中碰到过的一个问题,做此记录,便于以后查看.   include标签用法. ...

  2. 【Android 界面效果25】android中include标签的使用

    在一个项目中我们可能会需要用到相同的布局设计,如果都写在一个xml文件中,代码显得很冗余,并且可读性也很差,所以我们可以把相同布局的代码单独写成一个模块,然后用到的时候可以通过<include ...

  3. Android中include标签的使用

    在Android的开发中,我们知道布局文件可以让我们很方便的对各个UI控件进行位置安排跟属性设置,而在程序中可以直接取得控件并赋予对应操作功能.但是,如果是一个复杂的界面设计,我们把所有布局都放在一个 ...

  4. android中include

    android中include. include标签用法. 1.新建一个xml文件,命名 head.xml head.xml文件内容如下: <?xml version="1.0&quo ...

  5. 关于 Android 中未公开的类(用@hide隐藏的类)

    关于 Android 中未公开的类(用@hide隐藏的类) 摘自:http://wangsheng2008love.blog.163.com/blog/static/78201689201142643 ...

  6. android中include 的使用讲解

    include的作用就是重复使用同一段代码,提高代码的重用性.具体说就是,通过include 在 某布局 a.xml 中引用 B.xml布局文件,这个b.xml可同时被多个布局同时使用,所以达到了同一 ...

  7. mybatis中<include>标签的作用

    MyBatis中sql标签定义SQL片段,include标签引用,可以复用SQL片段 sql标签中id属性对应include标签中的refid属性.通过include标签将sql片段和原sql片段进行 ...

  8. django学习-7.html模板中include标签使用场景

    1.前言 假设一个公司A有一个网站B,且网站B有5个不同的页面分别为C1,C2,C3,C4,C5. 那么,我们在打开这5个不同页面后去查看页面的整体内容,会发现每个页面的顶部内容.底部内容都一模一样. ...

  9. Django 模板中 include 标签使用小结

    include 标签允许在模板中包含其它的模板的内容. 标签的参数是所要包含的模板名称,可以是一个变量,也可以是用单/双引号硬编码的字符串. 每当在多个模板中出现相同的代码时,就应该考虑是否要使用 { ...

随机推荐

  1. fbx模型

    [fbx模型] 1.FBX是Autodesk的一个用于跨平台的免费三维数据交换的格式(最早不是由Autodesk开发,但后来被其收购),目前被 众多的标准建模软件所支持,在游戏开发领域也常用来作为各种 ...

  2. SpringMVC简单的文件上传

    引入依赖包: <!-- 文件上传的依赖 --> <dependency> <groupId>commons-fileupload</groupId> & ...

  3. git配置多用户多平台

    在Git使用中经常会碰到多用户问题,例如:你在公司里有一个git账户,在github上有一个账户,并且你想在一台电脑上同时对这两个git账户进行操作,此时就需要进行git多用户配置. 首先配置不同的S ...

  4. Python编写两个数的加减法游戏

    目标: 1.实现两个数的加减法 2.回答者3次输错计算结果后,输出正确结果,并询问回答者是否继续 1.使用常规函数实现两个数的加减法游戏 代码如下: #!/usr/bin/env python # - ...

  5. Introduction to Partial View

    By Jignesh Trivedi on May 14, 2015 http://www.c-sharpcorner.com/UploadFile/ff2f08/partial-view-in-mv ...

  6. C# 操作Excel基础篇(读取Excel、写入Excel)

    注意事项:Excel的数据表中最多只能储存65535行数据,超出后,需要将数据分割开来进行储存.同时对于Excel中的乱码象限,是由于编码的错误方式导致引起的! 一.读取Excel数据表,获得Data ...

  7. jQuery form 插件

    http://jquery.malsup.com/form/#getting-started 举例: $(document).ready(function() { $('#ff').ajaxForm( ...

  8. win32的计数增减操作的原子操作--InterLockedIncrement和InterlockedDecrement

    InterLockedIncrement and InterLockedDecrement 实现数的原子性加减. 什么是原子性的加减呢? 举个例子:如果一个变量 Long value =0; 首先说一 ...

  9. HTML__图片轮播ion-slide-box

    先大概描述一下要做的界面: 从网络请求json数据,获取网络图征数据,然后轮播图片.我遇到的问题是:图片不显示,代码如下 <ion-slide-box does-continue="t ...

  10. wpf控件开发基础

    wpf控件开发基础(3) -属性系统(2) http://www.cnblogs.com/Clingingboy/archive/2010/02/01/1661370.html 这个有必要看看 wpf ...