• 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. 效果图:





  • 相关阅读:
    基于ABP落地领域驱动设计-04.领域服务和应用服务的最佳实践和原则
    基于ABP落地领域驱动设计-03.仓储和规约最佳实践和原则
    基于ABP落地领域驱动设计-02.聚合和聚合根的最佳实践和原则
    基于ABP落地领域驱动设计-01.全景图
    Es6-find&map&filter&reduce
    vue之监听事件
    list map互相转换
    springcloud 返回实体类忽略属性
    Apache NetBeans IDE 12.3 双击无反应怪事
    前端--- 前端调试经验总结
  • 原文地址:https://www.cnblogs.com/jh5240/p/2229235.html
Copyright © 2020-2023  润新知