zoukankan      html  css  js  c++  java
  • 安卓杂记(二)利用FrameLayout叠加多种view的方法

    一.FrameLayout介绍:

    FrameLayout是五大布局中最简单的一个布局,在这个布局中,整个界面被当成一块空白备用区域,所有的子元素都不能被指定放置的位置,它们统统放于这块区域的左上角,并且后面的子元素直接覆盖在前面的子元素之上,将前面的子元素部分和全部遮挡。

    1.在FrameLayout中添加普通的View

    在FrameLayout中可以添加诸如imageView和TextView这样简单的View,它们层层向上叠加,上层遮蔽下层,代码示例如下:

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <ImageView 
            android:id="@+id/image1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
              android:src="@drawable/sky"/>
        <ImageView 
            android:id="@+id/image2"
             android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/cloud"/>
        <ImageView 
            android:id="@+id/image3"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/sun"/>
    </FrameLayout>

    图片层层叠加,只显示上层图片

    2.在FrameLayout中利用<include>标签添加自定义的xml文件

     <FrameLayout
            android:id="@+id/circleView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
            
      
     
            
    	<include 
    	   layout="@layout/circle_view"/>
    
     
            <include    
               layout="@layout/circle_view2"/>
    	
        </FrameLayout>

    3.在FrameLayout中引用自定义的view类文件

     <FrameLayout
            android:id="@+id/circleView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
    
     
            
            <com.example.viewflipperdemoactivity.CircleView 
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"/>
            
    	
    	 <TextView
            	android:layout_width="fill_parent" />
     
        </FrameLayout>

    二.设置FrameLayout中的某个View透明

    由于FrameLayout层层叠加的特性,使得下层View被上层View遮蔽,有时为了让下层View可见,就不得不让上层View透明:

    View.getBackground().setAlpha(100);



     

  • 相关阅读:
    iptables防火墙--------基本操作
    iptables防火墙--------基本概念
    常用运维工具小结
    ELK6.6.0+filebeat6.6.0部署
    Yum安装时出现 The program yum-complete-transaction is found in the yum-utils package
    重温面向对象核心 下 : 你一定能看懂的委托和事件
    重温面向对象核心 上
    程序员创业第一步:如何获取第一笔风险投资
    MVC + EFCore 完整教程19-- 最简方法读取json配置:自定义configuration读取配置文件
    MVC+EFCore 完整教程18 -- 升级分布视图至 View Component
  • 原文地址:https://www.cnblogs.com/jscitlearningshare/p/4340649.html
Copyright © 2011-2022 走看看