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开发相关文章

最新文章

  1. 如何挂自己的web项目(免费拥有自己的网站及域名)
  2. 列表list
  3. 开发错误记录5-Failed&#160;to&#160;sync&#160;Gradle&#160;project&#160;‘HideTitleDemo’
  4. Redis 数据持久化(一)
  5. Cocoapods的安装与使用
  6. java与IOS之间的RSA加解密
  7. UVa 10969 (圆与圆之间的覆盖问题) Sweet Dream
  8. LWIP互联网资料汇总
  9. [置顶] 自己写sqlhelper类
  10. HTML中Select的使用具体解释
  11. BestCoder Round #67 (div.2) N*M bulbs
  12. split分割函数
  13. 如何用C语言封装 C++的类,在 C里面使用
  14. 【开发技术】java+mysql 更改表字段的步骤
  15. C++——STL内存清除
  16. 自学Aruba5.3.4-Aruba安全认证-有PEFNG 许可证环境的认证配置802.1x
  17. The Little Prince-12/16
  18. js实现环形菜单效果
  19. 绝对干货!!css3字体图标—丰富的阿里图标库iconfont的使用详解
  20. xp——极限编程的几个方法

热门文章

  1. Android系统移植与调试之------->安装apk时出现错误Failure [INSTALL_FAILED_DEXOPT]问题解决的方法
  2. Android底部菜单栏+顶部菜单
  3. c语言操作mysql数据库
  4. linux shell 字符串操作(长度,查找,替换)
  5. 面向对象分析与设计(C++)课堂笔记
  6. Data Structure Binary Tree: Lowest Common Ancestor in a Binary Tree
  7. 新手用的git配置命令
  8. shell 查看系统有关信息
  9. 《机器学习实战》学习笔记第十二章 —— FP-growth算法
  10. 算法(Algorithms)第4版 练习 1.3.32