今天在学习实现墨迹天气那样的拖动效果时,看到用的是重写FrameLayout。翻了翻书,突然想明白,为什么用FrameLayout.在FrameLayout中,用我看的书中的话说是,空间永远用不完。<?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"
android:background="#897753"
>
<ImageView
android:id="@+id/image1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="invisible"
android:src="@drawable/sky"/>
<ImageView
android:id="@+id/image2"
android:visibility="invisible"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/cloud"/>
<ImageView
android:id="@+id/image3"
android:visibility="invisible"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/sun"/>
</FrameLayout>
其中,image1、image2、image3都是在同一块空间的。可以说它们是重叠着的,界面显示的是最近用的那一个。在我的代码中把它们都先不可见。在整体代码中实现的是点一下屏幕就换一张图片。另外,我个人感觉,实现拖动效果的关键原理就是framelayout使得几部分空间的重叠。设置只有一部分可见。当拖动时,设置其他部分移动。发现下载附近要扣e币,我把代码也贴上,图片可以换成自己喜欢的~FramLayoutTestActivity.java
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageView;
public class FramLayoutTestActivity extends Activity {
private String TAG = "FramLayoutTestActivity";
private ImageView image1;
private ImageView image2;
private ImageView image3;
private List<ImageView> list;
private int count=0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image1=(ImageView)findViewById(R.id.image1);
image2=(ImageView)findViewById(R.id.image2);
image3=(ImageView)findViewById(R.id.image3);
list=new ArrayList<ImageView>();
list.add(image1);
list.add(image2);
list.add(image3);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction()==MotionEvent.ACTION_DOWN)
{
Log.i(TAG,"move---");
showImage();
}
return super.onTouchEvent(event);
}
private void showImage()
{
image1.setVisibility(View.VISIBLE);
count=count%3;
for(ImageView i:list)
{
i.setVisibility(View.INVISIBLE);
}
list.get(count).setVisibility(View.VISIBLE);
count++;
}
}
main.xml<?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"
android:background="#897753"
>
<ImageView
android:id="@+id/image1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="invisible"
android:src="@drawable/sky"/>
<ImageView
android:id="@+id/image2"
android:visibility="invisible"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/cloud"/>
<ImageView
android:id="@+id/image3"
android:visibility="invisible"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/sun"/>
</FrameLayout>
分享到:
相关推荐
Android中帧布局FrameLayout的常用属性.pdf 学习资料 复习资料 教学资源
android demo,FrameLayout的使用,该实例实现了一个美女在地图上的行走。
Android Framelayout显示静态和动态的扑克牌 包含Handler 和Timer TimerTask的使用方法
Android项目仿新浪微博下拉刷新继承FrameLayout.rar
Android中使用FrameLayout布局完成教学案例的要求说明.pdf 学习资料 复习资料 教学资源
Android中使用FrameLayout布局完成教学案例的代码清单.pdf 学习资料 复习资料 教学资源
Android中使用FrameLayout完成的图片浏览器练习题要求说明.pdf 学习资料 复习资料 教学资源
Android中使用FrameLayout完成的图片浏览器项目的代码清单.pdf 学习资料 复习资料 教学资源
Android中帧布局FrameLayout的特点.pdf 学习资料 复习资料 教学资源
19Android-04-frameLayout.mp4
ImageView和FrameLayout拥有手势控制和定位动画
本篇文章是对AnDroid FrameLayout的使用进行了详细的分析介绍,需要的朋友参考下
高仿新浪微博,采用FrameLayout布局的形式来实现下拉刷新。 在原程序的基础上添加了下拉刷新后listview列表内容的更新,更好的模拟刷新后的效果。 程序已在模拟器中测试通过,且效果很好。
主要介绍了Android布局之FrameLayout帧布局的相关资料,需要的朋友可以参考下
模仿墨迹天气的天气展示, 使用FrameLayout实现 目的是通过此列子展示FrameLayout的使用
在这个布局中,所有的子元素都不能被指定放置的位置,他们统统防御这块区域的左上角, 并且后面的子元素直接覆盖在前面的子元素之上,将前面的子元素部分和全部遮挡。 用途 常用于进度条的表示 <?xml version...
通过使用 FrameLayout 实现霓虹灯效果 在改变背景颜色时采用了逐级递增的方式,也就是说当前TextView的背景颜色 是上一次改变背景颜色时比当前TextView尺寸小的相邻的TextView的背景颜色。这样看起来像是某一种颜色...
Android入门第三篇之RelativeLayout、FrameLayout.docx
Android应用开发