Android 实现两个list分别出现(在某一时刻只出现一个控件)
第一种方法:
在.xml文件中将这两个List分别放入不同的布局管理器中,比如说
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" > <LinearLayout
android:id="@+id/citylist_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <ExpandableListView
android:id="@+id/expandablelist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="36.56"
android:background="#ffffff"
android:cacheColorHint="#00000000"
android:childDivider="@android:color/darker_gray"
android:divider="@android:color/black"
android:dividerHeight="1.5dip"
android:listSelector="#00000000" />
</LinearLayout> <LinearLayout android:id="@+id/localmap_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffcc99"
android:visibility="visible" > </ListView> </LinearLayout>
</RelativeLayout>
上面一个ExpandableListView 一个ListView分别放入两个
LinearLayout布局中。 在MainActivity.java文件中写入如下代码
LinearLayout cl = (LinearLayout) findViewById(R.id.citylist_layout);
LinearLayout lm = (LinearLayout) findViewById(R.id.localmap_layout);
lm.setVisibility(View.VISIBLE);
cl.setVisibility(View.GONE); LinearLayout cl = (LinearLayout) findViewById(R.id.citylist_layout);
LinearLayout lm = (LinearLayout) findViewById(R.id.localmap_layout);
lm.setVisibility(View.GONE);
cl.setVisibility(View.VISIBLE);
就可实现两个ListView在同一时刻只出现一个。
<友情提示 View.GONE 不要替换成 View.INVISIBLE 可能出错
希望能搞明白
View.GONE
View.VISIBLE
View.INVISIBLE
三者的区别
>
第二种方法:使用Fragment
需要注意的是,如果报错如
java.lang.IllegalStateException The specified child already has a parent. You must call removeView() on the child's parent first
我犯错的原因是在继承Fragment的子类实现方法
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState)
{
View =inflater.inflate(R.layout.xxx,contauner,true);
return v;
}
解决办法
1. 参数 true 改为 false
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState)
{
View =inflater.inflate(R.layout.xxx,contauner,false);
return v;
}
2改用另外一个方法参数
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState)
{
View =inflater.inflate(R.layout.xxx,null);
return v;
}
Android 实现两个list分别出现(在某一时刻只出现一个控件)的更多相关文章
- android 让一个控件按钮居于底部的几种方法
android 让一个控件按钮居于底部的几种方法1.采用linearlayout布局:android:layout_height="0dp" <!-- 这里不能设置fill_ ...
- [转]android 让一个控件按钮居于底部的几种方法
本文转自:http://www.cnblogs.com/zdz8207/archive/2012/12/13/2816906.html android 让一个控件按钮居于底部的几种方法 1.采用lin ...
- android自定义控件(6)-详解在onMeasure()方法中如何测量一个控件尺寸
今天的任务就是详细研究一下protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)方法.如果只是说要重写什么方法有什么 ...
- android:怎么实现一个控件与另一个指定控件左对齐
https://segmentfault.com/q/1010000003905460?_ea=425861 针对你这种情况,最简单的一种办法是,设置两个TextView的宽度为固定值,且相等. Li ...
- Android简易实战教程--第四十九话《满屏拖动的控件》
今天做个有意思的效果吧,控件的拖拽,简单实用,逻辑清晰点3分钟看完. 说的很高大上,其实就是拖动Button按钮跟着鼠标位置满手机屏幕跑罢了. 直接上简单的代码吧: public class Main ...
- android只设置部分控件随着软键盘的出现而腾出空间
转载请标明出处:https://www.cnblogs.com/tangZH/p/12013685.html 在项目过程中,出现了一个需求,软键盘要顶起部分控件,而另一部分控件不动. 关于这种需求,我 ...
- 【Android开发日记】之入门篇(十四)——Button控件+自定义Button控件
好久不见,又是一个新的学期开始了,为什么我感觉好惆怅啊!这一周也发生了不少事情,节假日放了三天的假(好久没有这么悠闲过了),实习公司那边被组长半强制性的要求去解决一个后台登陆的问题,结果就是把 ...
- Android基础控件TextClock和Chronometer的使用
1.简介 DigitalClock, TextClock,AnalogClock,Chronometer其中DigitalClock和AnalogClock废弃了! TextClock是在Androi ...
- Android开发之基本控件和详解四种布局方式
Android中的控件的使用方式和iOS中控件的使用方式基本相同,都是事件驱动.给控件添加事件也有接口回调和委托代理的方式.今天这篇博客就总结一下Android中常用的基本控件以及布局方式.说到布局方 ...
随机推荐
- node下的跨域传递cookie
研究背景: 最近有一位朋友找工作,需要面试,涉及到面试就涉及面试题,于是我想起来鄙人之前面试被问到的一个跨域传递cookie的问题.搜索了相关资料,但自己不敲一下肯定是不足以让人信服的. 我用node ...
- angular入门学习文档之一
一.数据双向绑定 angular(下面统一简称ng)强大的地方莫过于它内置的数据双向绑定功能,下面我们通过一个简单的例子来演示ng强大的双向绑定数据的能力. 代码如下: 1.dom结构: 1.< ...
- php $_SERVER['HTTP_USER_AGENT']
//获取浏览器 function getBrowse() { global $_SERVER; $Agent = $_SERVER['HTTP_USER_AGENT']; $browseinfo='' ...
- 使用flex布局调换两个按钮的位置
组件用的时antd的Modal组件,里面的按钮需要调换一下位置 今天发现用flex布局非常方便,代码如下: display: flex; justify-content: center; flex-f ...
- 通过域名访问部署在服务器上的javaweb项目
因为对域名访问什么也不了解,遇到问题就有种不知道从哪里下手的茫然,也就更不知道错在哪里,前前后后一共折腾了一天多,最后问了阿里客服才成功弄出来,因此记录一下. 关于服务器的购买.配置,及域名的备案解析 ...
- 【Java并发编程】之十三:生产者—消费者模型
生产者消费者问题是线程模型中的经典问题:生产者和消费者在同一时间段内共用同一存储空间,生产者向空间里生产数据,而消费者取走数据. 这里实现如下情况的生产--消费模型: 生产者不断交替地生产两组 ...
- BZOJ5101 POI2018Powódź(并查集)
如果某个格子的积水量超过了该格子的某个挡板高度,那么挡板另一端的积水量就会与其相同.看起来是一个不断合并的过程,考虑并查集.枚举深度,维护每个连通块内的方案数,深度超过某挡板高度时,将两端的连通块合并 ...
- MT【147】又见最大最小
(2018浙江省赛12题)设$a\in R$,且对任意的实数$b$均有$\max\limits_{x\in[0,1]}|x^2+ax+b|\ge1$求$a$的范围_____解答:由题意$\min\li ...
- 【BZOJ2957】楼房重建(线段树)
[BZOJ2957]楼房重建(线段树) 题面 BZOJ 题解 对于整个区间维护最大斜率以及只考虑这个区间的答案 考虑如何向上合并. 首先左半段的答案是一定存在的 所以,现在的问题就是右半段能够贡献的答 ...
- 【BZOJ1079】【SCOI2008】着色方案
Time Limit: 10 Sec Memory Limit: 162 MB Description 有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci ...