【转】 Pro Android学习笔记(二七):用户界面和控制(15):FrameLayout
FrameLayout
FrameLayout通常只包含一个控件。如果我们在FrameLayout中设置多个控件,则第二个控件会堆叠在第一个控件上面,如此类推,一层一层地叠上去。下面的例子,我们在FrameLayout中设置两个控件,一个可视,另一个不可视也不占位置(GONE),点击,通过设置可视属性,实现点击切换图片的视觉效果。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView android:id="@+id/imageViewOne"
android:src="@drawable/sunflower01"
android:scaleType="fitCenter"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView android:id="@+id/imageViewTwo"
android:src="@drawable/sky02"
android:scaleType="fitCenter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
</FrameLayout>
Java代码如下:
private ImageView one = null;
private ImageView two = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.ui_frame);
one = (ImageView)findViewById(R.id.imageViewOne);
two = (ImageView)findViewById(R.id.imageViewTwo);
one.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
two.setVisibility(View.VISIBLE);
one.setVisibility(View.GONE);
}
});
two.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
one.setVisibility(View.VISIBLE);
two.setVisibility(View.GONE);
}
});
}
FrameLayout一般用于单个控件,但是利用其将可控件堆叠的效果,可以设置一些特殊,如下面XML文件:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView android:id="@+id/imageViewOne"
android:src="@drawable/sunflower01"
android:scaleType="fitCenter"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView android:id="@+id/imageViewTwo"
android:src="@drawable/png13"
android:scaleType="center"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
相关链接: 我的Android开发相关文章
最新文章
- 如何挂自己的web项目(免费拥有自己的网站及域名)
- 列表list
- 开发错误记录5-Failed&#160;to&#160;sync&#160;Gradle&#160;project&#160;‘HideTitleDemo’
- Redis 数据持久化(一)
- Cocoapods的安装与使用
- java与IOS之间的RSA加解密
- UVa 10969 (圆与圆之间的覆盖问题) Sweet Dream
- LWIP互联网资料汇总
- [置顶] 自己写sqlhelper类
- HTML中Select的使用具体解释
- BestCoder Round #67 (div.2) N*M bulbs
- split分割函数
- 如何用C语言封装 C++的类,在 C里面使用
- 【开发技术】java+mysql 更改表字段的步骤
- C++——STL内存清除
- 自学Aruba5.3.4-Aruba安全认证-有PEFNG 许可证环境的认证配置802.1x
- The Little Prince-12/16
- js实现环形菜单效果
- 绝对干货!!css3字体图标—丰富的阿里图标库iconfont的使用详解
- xp——极限编程的几个方法
热门文章
- Android系统移植与调试之------->安装apk时出现错误Failure [INSTALL_FAILED_DEXOPT]问题解决的方法
- Android底部菜单栏+顶部菜单
- c语言操作mysql数据库
- linux shell 字符串操作(长度,查找,替换)
- 面向对象分析与设计(C++)课堂笔记
- Data Structure Binary Tree: Lowest Common Ancestor in a Binary Tree
- 新手用的git配置命令
- shell 查看系统有关信息
- 《机器学习实战》学习笔记第十二章 —— FP-growth算法
- 算法(Algorithms)第4版 练习 1.3.32