Android中include标签的使用(打开引用布局,隐藏当前布局)
在开发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标签的使用(打开引用布局,隐藏当前布局)的更多相关文章
- android中include标签使用详解
android中include标签是为了便于控件的覆用的一个很好解决方案. 但是也有一些需要注意的地方,下面是本人在项目中碰到过的一个问题,做此记录,便于以后查看. include标签用法. ...
- 【Android 界面效果25】android中include标签的使用
在一个项目中我们可能会需要用到相同的布局设计,如果都写在一个xml文件中,代码显得很冗余,并且可读性也很差,所以我们可以把相同布局的代码单独写成一个模块,然后用到的时候可以通过<include ...
- Android中include标签的使用
在Android的开发中,我们知道布局文件可以让我们很方便的对各个UI控件进行位置安排跟属性设置,而在程序中可以直接取得控件并赋予对应操作功能.但是,如果是一个复杂的界面设计,我们把所有布局都放在一个 ...
- android中include
android中include. include标签用法. 1.新建一个xml文件,命名 head.xml head.xml文件内容如下: <?xml version="1.0&quo ...
- 关于 Android 中未公开的类(用@hide隐藏的类)
关于 Android 中未公开的类(用@hide隐藏的类) 摘自:http://wangsheng2008love.blog.163.com/blog/static/78201689201142643 ...
- android中include 的使用讲解
include的作用就是重复使用同一段代码,提高代码的重用性.具体说就是,通过include 在 某布局 a.xml 中引用 B.xml布局文件,这个b.xml可同时被多个布局同时使用,所以达到了同一 ...
- mybatis中<include>标签的作用
MyBatis中sql标签定义SQL片段,include标签引用,可以复用SQL片段 sql标签中id属性对应include标签中的refid属性.通过include标签将sql片段和原sql片段进行 ...
- django学习-7.html模板中include标签使用场景
1.前言 假设一个公司A有一个网站B,且网站B有5个不同的页面分别为C1,C2,C3,C4,C5. 那么,我们在打开这5个不同页面后去查看页面的整体内容,会发现每个页面的顶部内容.底部内容都一模一样. ...
- Django 模板中 include 标签使用小结
include 标签允许在模板中包含其它的模板的内容. 标签的参数是所要包含的模板名称,可以是一个变量,也可以是用单/双引号硬编码的字符串. 每当在多个模板中出现相同的代码时,就应该考虑是否要使用 { ...
随机推荐
- 201671010140. 2016-2017-2 《Java程序设计》java学习第一周
java学习第一周 本周是新学期的开端,也是新的学习进程的开端,第一次接触java这门课程,首先书本的厚度就给我一种无形的压力,这注定了,这门课程不会是轻松的,同时一种全新的学习方 ...
- 用rand5()生成rand(n)
问题:有函数rand5(),它能够等概率生成[0,5)之间的整数.由rand5()构造rand(n)使其能够等概率生成[0,n)之间的整数. 思路1:有rand5()先生成等概率生成0和1的rand0 ...
- 【bzoj1614】[Usaco2007 Jan]Telephone Lines架设电话线
题目描述 Farmer John打算将电话线引到自己的农场,但电信公司并不打算为他提供免费服务.于是,FJ必须为此向电信公司支付一定的费用. FJ的农场周围分布着N(1 <= N < ...
- Composer安装(windows)
https://files.cnblogs.com/files/wlphp/Composer-Setup.zip 先下载这个安装包,一直下一步 然后设置composer全局中国景象 composer ...
- Arcgis engine编程报错查询(转)
Arcgis engine编程报错查询 标签: arcgis arcengine arcgisengine 2016年04月10日 17:29:35429人阅读 评论(0) 收藏 举报 分类: Ar ...
- sql去除重复记录 且保留id最小的 没用
第一步:查询重复记录 SELECT * FROM TableName WHERE RepeatFiled IN ( SELECT RepeatFiled FROM TableName ...
- sencha:日期选择组件datepicker
来源于<sencha touch权威指南> ------------------------------- 除app.js外,其它内容都与上一篇博客里的内容相同.app.js代码如下: E ...
- 10.IN 操作符
IN 操作符 IN 操作符允许我们在 WHERE 子句中规定多个值. SQL IN 语法 SELECT column_name(s) FROM table_name WHERE column_name ...
- jq获取table总行数
var rows = $('table').find("tr").length;
- LightOJ 1284 Lights inside 3D Grid (数学期望)
题意:在一个三维的空间,每个点都有一盏灯,开始全是关的.现在每次随机选两个点,把两个点之间的全部点,开关都按一遍,问k次过后开着的灯的期望数量: 析:很容易知道,如果一盏灯被按了奇数次,那么它肯定是开 ...