zoukankan      html  css  js  c++  java
  • ImagView

    1.TestImageViewActivity:

     1 import android.app.Activity;
    2 import android.os.Bundle;
    3 import android.os.Handler;
    4 import android.os.Message;
    5 import android.widget.ImageView;
    6 import android.widget.TextView;
    7
    8 public class TestImageViewActivity extends Activity
    9 {
    10 private ImageView imageView;
    11 private TextView textView;
    12 Handler handler = new Handler();
    13 int imag_alpha = 255;
    14 // 控件线程
    15 boolean isrung = false;
    16
    17 @Override
    18 public void onCreate(Bundle savedInstanceState)
    19 {
    20 super.onCreate(savedInstanceState);
    21 setContentView(R.layout.main);
    22 isrung = true;
    23 imageView = (ImageView) findViewById(R.id.ImagView01);
    24 imageView.setImageResource(R.drawable.kk);
    25 // 设置Alpha
    26 imageView.setAlpha(imag_alpha);
    27 textView = (TextView) findViewById(R.id.TextView01);
    28 new Thread(new Runnable()
    29 {
    30 @Override
    31 public void run()
    32 {
    33 while (isrung)
    34 {
    35 try
    36 {
    37 Thread.sleep(2000);
    38 update_alpha();
    39 }
    40 catch (InterruptedException e)
    41 {
    42 e.printStackTrace();
    43 }
    44 }
    45 }
    46 }).start();
    47 handler = new Handler()
    48 {
    49 @Override
    50 public void handleMessage(Message msg)
    51 {
    52 super.handleMessage(msg);
    53 imageView.setAlpha(imag_alpha);
    54 textView.setText("imag_alpha的值为:" + imag_alpha);
    55 // 更新
    56 imageView.invalidate();
    57 }
    58 };
    59 }
    60
    61 private void update_alpha()
    62 {
    63 if (imag_alpha >= 7)
    64 {
    65 imag_alpha -= 7;
    66 }
    67 else
    68 {
    69 isrung = false;
    70 }
    71 // 发送需要更新imagView视图的消息
    72 handler.sendMessage(handler.obtainMessage());
    73 }
    74 }

    2. /TestImageView/res/layout/main.xml:

    1 <?xml version="1.0" encoding="utf-8"?>
    2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3 android:orientation="vertical" android:layout_width="fill_parent"
    4 android:layout_height="fill_parent">
    5 <ImageView android:id="@+id/ImagView01" android:layout_width="fill_parent"
    6 android:layout_height="wrap_content" />
    7 <TextView android:id="@+id/TextView01" android:layout_below="@id/ImagView01"
    8 android:layout_width="fill_parent" android:layout_height="wrap_content" />
    9 </LinearLayout>

    3. 效果图:





  • 相关阅读:
    jquery 视觉特效(幻灯片效果)
    jquery 视觉特效(图片内容滑动浏览器)
    jquery之stop()的用法
    网站图片幻灯片效果之左右箭头的制作
    数据库三范式
    jquery 视觉特效(当鼠标悬停时,显示大图)
    jQuery EasyUI 1.2.6 新特性
    VM虚拟机网络设置
    Win7:修改注册表来更改“桌面”、“我的文档”、“收藏夹”的位置
    jQuery EasyUI API 中文文档 数字滑块(Slider)
  • 原文地址:https://www.cnblogs.com/jh5240/p/2229235.html
Copyright © 2011-2022 走看看