使用FrameLayout(帧布局) 和Timer实现动态图片
来源:互联网 发布:微分销系统开发源码 编辑:程序博客网 时间:2024/05/29 13:45
1.实现图片的轮换显示,定义帧布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="0,1,2,3"><TableRow><TextView android:text="水果"></TextView><TextView android:text="西瓜 "></TextView><TextView android:text="香蕉"></TextView><TextView android:text="芒果"></TextView></TableRow><TableRow><TextView android:text="language"></TextView><TextView android:text="中文 "></TextView><TextView android:text="英文"></TextView><TextView android:text="日语"></TextView></TableRow><TableRow><TextView android:text="编程语言"></TextView><TextView android:text="C "></TextView><TextView android:text="C++"></TextView><TextView android:text="Java"></TextView></TableRow></TableLayout>
<!--上面的表格布局可以忽略 --><FrameLayout android:id="@+id/frame" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"/></LinearLayout>
2.java 代码:
public class MainActivity extends Activity {private FrameLayout frameLayout=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //获取布局对象 frameLayout=(FrameLayout) findViewById(R.id.frame); //使用计时器 Timer timer=new Timer(); timer.scheduleAtFixedRate(new TimerTask() {int i=0;@Overridepublic void run() {i++;System.out.println(i);Message msg=new Message();msg.what=i;i%=3;//发送消息handler.sendMessage(msg);}}, 1000, 1000); } //使用Handler实现UI线程与Timer线程之间的通信 Handler handler=new Handler(){ //处理消息更新UI线程@Overridepublic void handleMessage(Message msg) {switch(msg.what){case 1:frameLayout.setForeground(getResources().getDrawable(R.drawable.f));;break;case 2:frameLayout.setForeground(getResources().getDrawable(R.drawable.s));break;case 3:frameLayout.setForeground(getResources().getDrawable(R.drawable.t));break;default:System.out.println("哈哈,没有图片");break;}} };}
3.在drawable中放了3张图片 f.png,s.png,t.png
- 使用FrameLayout(帧布局) 和Timer实现动态图片
- Android 动态布局实践 - 使用FrameLayout
- 【Android】使用FrameLayout布局实现霓虹灯效果
- 帧布局FrameLayout实现霓虹灯效果
- FrameLayout(帧布局)实现闪烁霓虹灯效果
- Kotlin实现动态添加Fragment碎片到FrameLayout布局中
- 帧布局(FrameLayout)的简单使用
- Android 布局 Framelayout 使用
- FrameLayout和布局优化
- FrameLayout 和 RadioGroup 布局
- FrameLayout和RadioGroup布局
- FrameLayout(层布局或者帧布局)的使用
- 使用TabHost和FrameLayout实现导航
- 使用FrameLayout+ScrollView+RelativeLayout嵌套布局,实现仿Windows Phone
- 10 - 布局Layout:FrameLayout帧布局以及FrameLayout在切换屏幕效果的使用
- FrameLayout(单帧布局)
- FrameLayout(帧布局)
- FrameLayout(帧布局)
- 冒泡排序(bubble sort)
- C6000系列DSP的GPIO模块
- glLoadIdentity()与glTranslatef()和glRotatef()--坐标变换
- Spring学习笔记---AOP的简单实例
- “移动优先” 14名投资人入围福布斯全球最佳
- 使用FrameLayout(帧布局) 和Timer实现动态图片
- Android资源文件
- 项目管理里程碑事件及相关
- mysql 數據優化
- hadoop Windows下privilegedActionException解决方法
- X Window 程式设计入门
- c++实现对windwos 下socket 的封装(实现封包及拆包处理)
- 一封程序员的苦逼辞职信
- python non-block socket 的问题