zoukankan      html  css  js  c++  java
  • AndroidUI设计 之 图片浏览器

    图片浏览器效果图 : 

    源码下载地址 : 

    -- CSDN : http://download.csdn.net/detail/han1202012/6875083

    -- GitHub : https://github.com/han1202012/AndroidPictureViewer.git


     

    一. 图片浏览器显示界面ImageView介绍

     

    1. ImageView的上下继承结构

     

    下面是API中的结构

    java.lang.Object
       ↳ android.view.View
        android.widget.ImageView
    Known Direct Subclasses
    Known Indirect Subclasses
     

    绘制成UML图 : 


     

    通过上面的分析 : ImageView有两个子类 ImageButton 和 QuickContactBadge, ImageButton还有一个子类是 ZoomButton;

     

    2. XML文件属性

     

    调整边界, 保持长宽比 :android:adjustViewBounds, setAdjustViewBounds(boolean), 是否调整自己的边界, 用来保持图片的长宽比例, 该属性与 android:maxHeight 和 android:maxWidth 属性一起使用才有效果, 单独使用没有效果;

     

    设置最大宽度, 高度 :android:maxWidth(android:maxHeight), setMaxWidth(int)[setMaxHeight(int)], 该属性需要与android:adjustViewBounds属性一起使用,单独使用无效果

    -- 设置图片固定大小, 同时保持长宽比 : a. 设置android:adjustViewBounds 为 true; b. 设置最大宽度, 高度; c. 设置android:layout_width 与 android:layout_height 值为 warp_content;

     

    裁剪保留空白 :android:cropToPadding, setCropToPadding(boolean), 是否裁剪, 用来保留ImageView的padding, 该属性与android:scrollY 属性一起使用的时候才有用, 单独使用没有效果; 即 在滚动的时候, 滚动到边界, 边界的padding空白是否显示;

     

    填充方式 :android:scaleType, setScaleType(ImageView.ScaleType), 设置图片缩放类型以适配ImageView大小, 即填充方式;

    可能的取值 : matrix, fitXY, fitStart, fitCenter, fitEnd, center, centerCrop, centerInside;

    -- matrix : 方法中的常量值为 ImageView.ScaleType.MATRIX, 使用矩阵来进行绘图;

    -- fitXY : 方法中的常量值为 ImageView.ScaleType.FIT_XY, 在x y 两个方向上缩放, 使图片完全填充整个ImageView 不按照长宽比例缩放;

    -- fitStart : 方法中的常量值为 ImageView.ScaleType.FIT_START, 保持长宽比缩放, 直到该图片完全显示在ImageView中, 缩放完成之后该图片在左上角;

    -- fitCenter : 方法中的常量值为 ImageView.ScaleType.FIT_CENTER, 保持长宽比缩放, 直到该图片完全显示在ImageView中, 缩放完成之后该图片位于中央;

    -- fitEnd : 方法中的常量值为 ImageView.ScaleType.FIT_END, 保持长宽比缩放, 直到该图片完全显示在ImageView中, 缩放完成之后该图片位于右下角;

    -- center : 方法中的常量值为 ImageView.ScaleType.CENTER, 将图片放在ImageView的中央, 不进行缩放;

    -- centerCrop : 方法中的常量值为 ImageView.ScaleType.CENTER_CROP, 保持长宽比缩放, 使图片完全覆盖ImageView;

    -- centerInside : 方法中的常量值为 ImageView.ScaleType.CENTER_INSIDE, 保持长宽比缩放, 是的ImageView完全显示图片;

     

    实例 : 

    XML文件 : 

     
    1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    2.     xmlns:tools="http://schemas.android.com/tools"  
    3.     android:layout_width="match_parent"  
    4.     android:layout_height="match_parent"  
    5.     android:orientation="vertical">  
    6.   
    7.     <ImageView   
    8.         android:id="@+id/im"  
    9.         android:background="#00FF00"  
    10.         android:layout_height="300dp"  
    11.         android:layout_width="300dp"  
    12.         android:src="@drawable/pic"  
    13.         <strong>android:scaleType</strong>="matrix"/>  
    14.   
    15. </LinearLayout>  


    修改其中的 android:scaleType属性值, 查看其中的差异 : 

    原图 : 


     

    android:scaleType 默认情况下 : 


     

    android:scaleType = "matrix" : 由下图可以看出, ImageView中的图片宽度与原图一样, 该属性不进行任何缩放,直接将图片放在左上角;


     

    android:scaleType = "fixXY" : 长宽不按比例拉伸, 图片明显变形 : 


     

    android:scaleType = "fitStart" , 图片按比例缩放, 宽先达到边界, 图片位于上边; 如果高先达到边界, 图片位于左边;


     

    android:scaleType = "fieCenter" ,长宽按照比例缩放, 宽度先达到边界, 上下有空白; 如果高度先达到边界, 那么左右有空白;

    android:scaleType = "fitEnd" , 长宽等比例缩放, 宽度先达到边界, 位于下边; 如果高度先达到边界, 位于右边;


     

    android:scaleType = "center" ,长宽不进行缩放, 图片的中心 与 ImageView 的中心重合;


     

    android:scaleType = "centerCrop" ,长宽等比例缩放, 使图片完全覆盖ImageView, 图片中心与ImageView中心重合, 使图片最短的边能覆盖ImageView边界;


     

    android:scaleType = "centerInside" ,长宽等比例缩放, 如果图片宽高小于等于ImageView宽高, 那么就按照原图大小显示; 如果图片大于ImageView, 那么按照等比例缩小直到能完全显示为止;


     

    3. ImageView常用方法

     

    设置图片 : 

    -- 设置位图 : setImageBitmap(bitmap), 为ImageView设置Bitmap位图显示;

    -- 设置Drawable : setImageDrawable(drawable), 为ImageView设置Drawable显示;

    -- 设置资源 : setImageResource(int), 为ImageView设置资源图片;

    -- 设置路径 : setImageUri(uri), 为ImageView设置图片路径, 显示该路径的图片;

     

    二. 图片浏览器操作介绍

     

    1. 实现左右循环切换图片

     

    图片数组 : 将图片放在数组中, ImageView显示数组中的图片;

     

    当前显示图片下标索引 : 设置一个int值, 用来表示当前显示图片数组中的图片, 这个值不是int下标, 这个值设置很大设置成Integer.MAXVALUE / 2, 该值与图片数组的长度进行取模运算结果就是当前显示的图片数组下标值;

     

    翻页操作 : 上一页操作就将当前显示索引自减1, 然后模上 图片数组大小; 下一页就将当前索引自增1, 然后模上 图片数组大小;

     

    代码示例 : 

     
    1. //设置一个很大的值, 保证前后翻页不会出现异常  
    2. currentImage = Integer.MAX_VALUE / 2;   
    3. //为了保证图片能够循环, 这里模运算是关键, 显示图片的下标始终是长度的模  
    4. image_all.setImageResource(images[ ++currentImage % images.length ]);  
    5. image_all.setImageResource(images[ --currentImage % images.length ]);  

    2. 透明度改变

     

    设置当前透明度 : 设置一个当前透明度值, 初始值为255, 255是不透明, 0为完全透明;

     

    透明度改变 : 当点击透明度增加按钮的时候, 透明度自增20, 如果结果透明度大于255, 那么改透明度强制设置为255; 当点击透明度见效按钮的时候, 透明度自减20, 当透明度小于0的时候, 透明度强制设置为0;

     

    代码示例 : 

     
    1. //透明度初始值  
    2. alpha = 255;  
    3. //透明度增加  
    4. alpha += 20;  
    5. if(alpha >= 255)  
    6.     alpha = 255;  
    7. image_all.setAlpha(alpha);  
    8. //透明度减小  
    9. alpha -= 20;  
    10. if(alpha <= 0)  
    11.     alpha = 0;  
    12. image_all.setAlpha(alpha);  

    3. 图片的放大缩小

     

    获取View组件宽高 : 在Activity普通方法中无法获取到view组件的准确值, 如果想要获取view组件的宽高, 可以在 onWindowFocusChanged()方法中获取;

     

    计算每次自增自减的单位值 : 当按下缩放按钮的时候, 就对ImageView的宽高值进行自增自减单位值操作;

     

    为ImageView设置宽高 : 即设置LayoutParams, 注意是LinearLayout.LayoutParams对象;

     

    代码示例 : 

    获取宽高 : 

     
    1. @Override  
    2. public void onWindowFocusChanged(boolean hasFocus) {  
    3.     // TODO Auto-generated method stub  
    4.     super.onWindowFocusChanged(hasFocus);  
    5.     //获取ImageView组件的宽高  
    6.     imageWidth = image_all.getWidth();  
    7.     imageHeight = image_all.getHeight();  
    8.       
    9.     //计算每次自增自减的值  
    10.     addWidth = imageWidth / 5;  
    11.     addHeight = imageHeight / 5;  
    12. }  

    缩放图片操作 : 

     

    1. case R.id.big:          //放大图片  
    2.     imageWidth += addWidth;  
    3.     imageHeight += addHeight;  
    4.           
    5.     image_all.setLayoutParams(new LinearLayout.LayoutParams(imageWidth, imageHeight));  
    6.     break;  
    7.       
    8. case R.id.small:        //缩小图片  
    9.     imageWidth -= addWidth;  
    10.     imageHeight -= addHeight;  
    11.     if(imageWidth <= 0 || imageHeight <=0){  
    12.         imageWidth += addWidth;  
    13.         imageHeight += addHeight;  
    14.     }  
    15.       
    16.     image_all.setLayoutParams(new LinearLayout.LayoutParams(imageWidth, imageHeight));  
    17.     break;  



    4. 旋转图片操作

     

    设置Matrix对象 : 该对象用来存放图像的旋转角度;

     

    设置旋转角度 : matrix.setRotate(), 即可设置旋转角度;

     

    创建Bitmap : 创建一个位图, 注意将设置了旋转角度的 matrix 设置上去;

     

    源码示例 :  

    1. matrix = new Matrix();  
    2.   
    3. //向左旋转进行的操作  
    4. anglel += 45;  
    5. matrix.setRotate(anglel);  
    6. Bitmap bitmap = ((BitmapDrawable) getResources().getDrawable(images[currentImage % images.length])).getBitmap();  
    7. bitmap = Bitmap.createBitmap(bitmap, 00, bitmap.getWidth(),bitmap.getHeight(), matrix, true);   
    8. image_all.setImageBitmap(bitmap);  
    9.   
    10. //向右旋转进行的操作  
    11. anglel -= 45;  
    12. matrix.setRotate(anglel);  
    13. Bitmap bitmap1 = ((BitmapDrawable) getResources().getDrawable(images[currentImage % images.length])).getBitmap();  
    14. bitmap1 = Bitmap.createBitmap(bitmap1, 00, bitmap1.getWidth(),bitmap1.getHeight(), matrix, true);   
    15. image_all.setImageBitmap(bitmap1);  



    三. 图片浏览器源码 

     

    XML布局文件 :  

    1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    2.     xmlns:tools="http://schemas.android.com/tools"  
    3.     android:layout_width="match_parent"  
    4.     android:layout_height="match_parent"  
    5.     android:background="@drawable/bg_im"  
    6.     android:orientation="vertical">  
    7.   
    8.     <LinearLayout   
    9.         android:orientation="horizontal"  
    10.         android:layout_height="wrap_content"  
    11.         android:layout_width="fill_parent"  
    12.         android:padding="5dp"  
    13.         android:gravity="center">  
    14.           
    15.         <Button   
    16.             android:id="@+id/alpha_plus"  
    17.             android:layout_height="fill_parent"  
    18.             android:layout_width="fill_parent"  
    19.             android:layout_weight="1"  
    20.             android:text="透明度+"  
    21.             android:background="@drawable/bg_bt"  
    22.             android:onClick="onClick"/>  
    23.           
    24.         <Button   
    25.             android:id="@+id/alpha_minus"  
    26.             android:layout_height="fill_parent"  
    27.             android:layout_width="fill_parent"  
    28.             android:layout_weight="1"  
    29.             android:text="透明度-"  
    30.             android:background="@drawable/bg_bt"  
    31.             android:onClick="onClick"/>  
    32.           
    33.         <Button   
    34.             android:id="@+id/prev_page"  
    35.             android:layout_height="fill_parent"  
    36.             android:layout_width="fill_parent"  
    37.             android:layout_weight="1"  
    38.             android:text="上一张"  
    39.             android:background="@drawable/bg_bt"  
    40.             android:onClick="onClick"/>  
    41.           
    42.         <Button   
    43.             android:id="@+id/next_page"  
    44.             android:layout_height="fill_parent"  
    45.             android:layout_width="fill_parent"  
    46.             android:layout_weight="1"  
    47.             android:text="下一张"  
    48.             android:background="@drawable/bg_bt"  
    49.             android:onClick="onClick"/>  
    50.           
    51.     </LinearLayout>  
    52.       
    53.     <LinearLayout   
    54.         android:orientation="horizontal"  
    55.         android:layout_height="wrap_content"  
    56.         android:layout_width="fill_parent"  
    57.         android:padding="5dp"  
    58.         android:gravity="center">  
    59.           
    60.         <Button   
    61.             android:id="@+id/big"  
    62.             android:layout_height="fill_parent"  
    63.             android:layout_width="fill_parent"  
    64.             android:layout_weight="1"  
    65.             android:text="放大"  
    66.             android:background="@drawable/bg_bt"  
    67.             android:onClick="onClick"/>  
    68.           
    69.         <Button   
    70.             android:id="@+id/small"  
    71.             android:layout_height="fill_parent"  
    72.             android:layout_width="fill_parent"  
    73.             android:layout_weight="1"  
    74.             android:text="缩小"  
    75.             android:background="@drawable/bg_bt"  
    76.             android:onClick="onClick"/>  
    77.           
    78.         <Button   
    79.             android:id="@+id/turn_left"  
    80.             android:layout_height="fill_parent"  
    81.             android:layout_width="fill_parent"  
    82.             android:layout_weight="1"  
    83.             android:text="左转"  
    84.             android:background="@drawable/bg_bt"  
    85.             android:onClick="onClick"/>  
    86.           
    87.         <Button   
    88.             android:id="@+id/turn_right"  
    89.             android:layout_height="fill_parent"  
    90.             android:layout_width="fill_parent"  
    91.             android:layout_weight="1"  
    92.             android:text="右转"  
    93.             android:background="@drawable/bg_bt"  
    94.             android:onClick="onClick"/>  
    95.           
    96.     </LinearLayout>  
    97.       
    98.     <ImageView   
    99.         android:id="@+id/image_all"  
    100.         android:layout_width="fill_parent"  
    101.         android:layout_height="fill_parent"  
    102.         android:scaleType="fitCenter"  
    103.         android:src="@drawable/mary1"/>  
    104.   
    105. </LinearLayout>  


    Drawable资源 : 

     

    整个界面的背景 : 渐变的颜色  

    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <shape xmlns:android="http://schemas.android.com/apk/res/android" >  
    3.     <gradient   
    4.         android:startColor="#A9F5A9"  
    5.         android:centerColor="#2EFE2E"  
    6.         android:endColor="#A9F5A9"  
    7.         android:type="linear"/>  
    8. </shape>  


    按钮的背景 : 两个9patch图片, 按下的时候按钮背景会改变 

      

    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <selector xmlns:android="http://schemas.android.com/apk/res/android" >  
    3.       
    4.     <item android:state_pressed="true"  
    5.         android:drawable="@drawable/bt_focus"></item>  
    6.       
    7.     <item android:state_pressed="false"  
    8.         android:drawable="@drawable/bt_normal"></item>  
    9.   
    10. </selector>  

     

    主Activity核心代码 :  

    1. package shuliang.han.imageview_test;  
    2.   
    3. import android.app.Activity;  
    4. import android.graphics.Bitmap;  
    5. import android.graphics.Matrix;  
    6. import android.graphics.drawable.BitmapDrawable;  
    7. import android.os.Bundle;  
    8. import android.view.View;  
    9. import android.widget.ImageView;  
    10. import android.widget.LinearLayout;  
    11.   
    12. public class MainActivity extends Activity {  
    13.   
    14.     private int[] images;       //图片资源id数组  
    15.     private int currentImage;   //当前显示图片  
    16.     private int alpha;          //透明度  
    17.       
    18.     private Matrix matrix;  
    19.     private int anglel;         //角度  
    20.       
    21.     private int imageWidth;  
    22.     private int imageHeight;  
    23.       
    24.     private int addWidth;  
    25.     private int addHeight;  
    26.       
    27.     private ImageView image_all;  
    28.       
    29.     @Override  
    30.     protected void onCreate(Bundle savedInstanceState) {  
    31.         super.onCreate(savedInstanceState);  
    32.         setContentView(R.layout.activity_main);  
    33.           
    34.         init();  
    35.           
    36.     }  
    37.       
    38.     //初始化成员变量  
    39.     private void init() {  
    40.         images = new int[]{R.drawable.mary1, R.drawable.mary2};  
    41.         currentImage = Integer.MAX_VALUE / 2;  
    42.         alpha = 255;  
    43.           
    44.         matrix = new Matrix();  
    45.           
    46.         image_all = (ImageView) findViewById(R.id.image_all);  
    47.         image_all.setImageResource(images[currentImage % images.length]);  
    48.     }  
    49.       
    50.     public void onClick(View view) {  
    51.         int id = view.getId();  
    52.           
    53.         switch (id) {  
    54.             case R.id.alpha_plus:   //增大透明度  
    55.                 alpha += 20;  
    56.                 if(alpha >= 255)  
    57.                     alpha = 255;  
    58.                 image_all.setAlpha(alpha);  
    59.                 break;  
    60.                   
    61.             case R.id.alpha_minus:  //减小透明度  
    62.                 alpha -= 20;  
    63.                 if(alpha <= 0)  
    64.                     alpha = 0;  
    65.                 image_all.setAlpha(alpha);  
    66.                 break;  
    67.                   
    68.             case R.id.next_page:    //显示下一张图片  
    69.                 //为了保证图片能够循环, 这里模运算是关键, 显示图片的下标始终是长度的模  
    70.                 image_all.setImageResource(images[ ++currentImage % images.length ]);  
    71.                 break;  
    72.               
    73.             case R.id.prev_page:    //显示上一张图片  
    74.                 image_all.setImageResource(images[ --currentImage % images.length ]);  
    75.                 break;  
    76.                   
    77.             case R.id.big:          //放大图片  
    78.                 imageWidth += addWidth;  
    79.                 imageHeight += addHeight;  
    80.                       
    81.                 image_all.setLayoutParams(new LinearLayout.LayoutParams(imageWidth, imageHeight));  
    82.                 break;  
    83.                   
    84.             case R.id.small:        //缩小图片  
    85.                 imageWidth -= addWidth;  
    86.                 imageHeight -= addHeight;  
    87.                 if(imageWidth <= 0 || imageHeight <=0){  
    88.                     imageWidth += addWidth;  
    89.                     imageHeight += addHeight;  
    90.                 }  
    91.                   
    92.                 image_all.setLayoutParams(new LinearLayout.LayoutParams(imageWidth, imageHeight));  
    93.                 break;  
    94.                   
    95.             case R.id.turn_left:    //向左旋转  
    96.                 anglel += 45;  
    97.                 matrix.setRotate(anglel);  
    98.                 Bitmap bitmap = ((BitmapDrawable) getResources().getDrawable(images[currentImage % images.length])).getBitmap();  
    99.                 bitmap = Bitmap.createBitmap(bitmap, 00, bitmap.getWidth(),bitmap.getHeight(), matrix, true);   
    100.                 image_all.setImageBitmap(bitmap);  
    101.                 break;  
    102.                   
    103.             case R.id.turn_right:   //向右旋转  
    104.                 anglel -= 45;  
    105.                 matrix.setRotate(anglel);  
    106.                 Bitmap bitmap1 = ((BitmapDrawable) getResources().getDrawable(images[currentImage % images.length])).getBitmap();  
    107.                 bitmap1 = Bitmap.createBitmap(bitmap1, 00, bitmap1.getWidth(),bitmap1.getHeight(), matrix, true);   
    108.                 image_all.setImageBitmap(bitmap1);  
    109.                 break;  
    110.                   
    111.             default:  
    112.                 break;  
    113.         }  
    114.     }  
    115.       
    116.     @Override  
    117.     public void onWindowFocusChanged(boolean hasFocus) {  
    118.         // TODO Auto-generated method stub  
    119.         super.onWindowFocusChanged(hasFocus);  
    120.         //获取ImageView组件的宽高  
    121.         imageWidth = image_all.getWidth();  
    122.         imageHeight = image_all.getHeight();  
    123.           
    124.         //计算每次自增自减的值  
    125.         addWidth = imageWidth / 5;  
    126.         addHeight = imageHeight / 5;  
    127.     }  
    128. }  



    四. ZoomButton 和 QuickContactBadge

     

    示例效果图 : 

    下载地址 : 

    GitHub : https://github.com/han1202012/ZoomButton_QuickContactBadge.git


     

    1. ZoomButton

     

    ZoomButton按钮 : ZoomButton按钮提供放大 缩小两个按钮, 两个按钮;

    ZoomControls按钮 : 该按钮会自动生成一组两个按钮, 两个按钮分别是放大和缩小;

    按钮点击切换背景 : 设置selector资源, 设置两个item, 一个item的状态为按下时, 显示一个图片, 另一个item的状态为普通情况下, 显示另一个图片; 

     

    selector源码 :  

    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <selector xmlns:android="http://schemas.android.com/apk/res/android" >  
    3.       
    4.     <item android:state_pressed="true"   
    5.         android:drawable="@drawable/app3"></item>  
    6.       
    7.     <item android:state_pressed="false"   
    8.         android:drawable="@drawable/app4"></item>  
    9.   
    10. </selector>  

    XML源码 : 

     

    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    3.     android:layout_width="match_parent"  
    4.     android:layout_height="match_parent"  
    5.     android:orientation="vertical" >  
    6.       
    7.     <ImageButton   
    8.         android:layout_width="wrap_content"  
    9.         android:layout_height="wrap_content"  
    10.         android:layout_gravity="center_horizontal"  
    11.         android:background="@drawable/app2"/>  
    12.       
    13.     <ImageButton   
    14.         android:layout_width="wrap_content"  
    15.         android:layout_height="wrap_content"  
    16.         android:layout_gravity="center_horizontal"  
    17.         android:background="@drawable/bt_bg"/>  
    18.       
    19.     <LinearLayout   
    20.         android:layout_width="wrap_content"  
    21.         android:layout_height="wrap_content"  
    22.         android:padding="10dp"  
    23.         android:layout_gravity="center_horizontal">  
    24.           
    25.         <ZoomButton   
    26.             android:id="@+id/zoom_1"  
    27.             android:layout_height="wrap_content"  
    28.             android:layout_width="wrap_content"  
    29.             android:src="@android:drawable/btn_minus"/>  
    30.           
    31.         <ZoomButton   
    32.             android:id="@+id/zoom_2"  
    33.             android:layout_height="wrap_content"  
    34.             android:layout_width="wrap_content"  
    35.             android:src="@android:drawable/btn_plus"/>  
    36.           
    37.     </LinearLayout>      
    38.       
    39.     <ZoomControls   
    40.         android:id="@+id/zoom_ctrl"  
    41.         android:layout_width="wrap_content"  
    42.         android:layout_height="wrap_content"  
    43.         android:layout_gravity="center_horizontal"/>  
    44.   
    45. </LinearLayout>  

    2. QuickContactBadge

     

    本质 : QuickContactBadge 也是图片, 可以通过android:src 指定图片;

     

    功能 : QuickContactBadge 可以关联手机通讯录中的联系人, 当点击图片的时候, 会弹出该联系人相关的界面;

    -- 关联方法 : 

    --- 使用邮箱关联 : assignContactFromEmail(String address, boolean lazyLookup), 将图片关联到指定email联系人;

    --- 使用号码关联 : assignContactFromPhone(String number, boolean lazyLookup), 将图片关联到指定电话联系人;

    --- 使用Uri关联 :  assignContactUri(Uri uri), 将图片关联到Uri对应的联系人;

     

     

    XML代码 

     
    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    3.     android:layout_width="match_parent"  
    4.     android:layout_height="match_parent"  
    5.     android:orientation="vertical" >  
    6.       
    7.     <QuickContactBadge   
    8.         android:id="@+id/badge"  
    9.         android:layout_width="wrap_content"  
    10.         android:layout_height="wrap_content"  
    11.         android:src="@drawable/app5"/>  
    12.   
    13. </LinearLayout>  



    Activity代码 : 

      

      1. package shuliang.han.zoombutton_quickcontactbadge;  
      2.   
      3. import android.app.Activity;  
      4. import android.os.Bundle;  
      5. import android.widget.QuickContactBadge;  
      6. import shuliang.han.zoombutton_quickcontactbadge.R;  
      7.   
      8. public class QuickContactBadgeActivity extends Activity {  
      9.   
      10.     private QuickContactBadge badge;  
      11.       
      12.     @Override  
      13.     protected void onCreate(Bundle savedInstanceState) {  
      14.         super.onCreate(savedInstanceState);  
      15.         setContentView(R.layout.quick_contact_badge);  
      16.           
      17.         badge = (QuickContactBadge) findViewById(R.id.badge);  
      18.         badge.assignContactFromPhone("120"false);  
      19.           
      20.     }  
      21.       
      22. }  
  • 相关阅读:
    yzoj P2344 斯卡布罗集市 题解
    yzoj P2350 逃离洞穴 题解
    yzoj P2349 取数 题解
    JXOI 2017 颜色 题解
    NOIP 2009 最优贸易 题解
    CH 4302 Interval GCD 题解
    CH4301 Can you answer on these queries III 题解
    Luogu2533[AHOI2012]信号塔
    Luogu3320[SDOI2015]寻宝游戏
    Luogu3187[HNOI2007]最小矩形覆盖
  • 原文地址:https://www.cnblogs.com/android100/p/AndroidUI-pic-explorer.html
Copyright © 2011-2022 走看看