android自定义绘图控件,绘图所占画布比例过小

卫星分布图在画布中所在比例太小。可能和图片本身太小有关。

原代码:

****************************************************************************************************************************************************************************************

页面显示:

gps_view_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/satellites_bg"
    >
    <TextView android:id="@+id/gps_status_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"  
        android:text="状态"/>
        
    <TextView android:id="@+id/lonlat_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"  
        android:text="0 0"/>
    //自定义控件显示卫星分布状态图
    <ylybbs.study.mygpstest.SatellitesView
        android:id="@+id/satellitesView"
        android:layout_width="match_parent"
        android:layout_height="fill_parent" />
    
</LinearLayout>

====================================================================================================================================

绘图java文件关键语句

compassBitmap = BitmapFactory.decodeResource(res, R.drawable.bg_satellite);
compassRadius = compassBitmap.getWidth() / 2;

****************************************************************************************************************************************************************************************

改进JAVA文件代码:对进行

compassBitmap = BitmapFactory.decodeResource(res, R.drawable.bg_satellite);

//增加一个语句,进行

compassBitmap = Bitmap.createScaledBitmap(compassBitmap,600,600,true);

compassRadius = compassBitmap.getWidth() / 2;

***************************************************************************************************************************************************************************************

效果图:

****************************************************************************************************************************************************************************************

public static Bitmap createScaledBitmap (Bitmap src, int dstWidth, int dstHeight, boolean filter) 函数用法:

public static Bitmap createScaledBitmap (Bitmap src, int dstWidth, int dstHeight, boolean filter)

从当前存在的位图,按一定的比例创建一个新的位图。

参数

src        用来构建子集的源位图

                 dstWidth   新位图期望的宽度

                 dstHeight  新位图期望的高度

       filter   如果是放大图片,filter决定是否平滑,如果是缩小图片,filter无影响

    返回值

             一个新的按比例变化的位图。


  1. /** 
  2.      * 修改图片的大小(从当前存在的位图,按一定的比例创建一个新的位图)<br> 
  3.      * 方 法 名:createScaledBitmap <br> 
  4.      * 创 建 人: <br> 
  5.      * 创建时间:2016-6-7 上午9:14:47 <br> 
  6.      * 修 改 人: <br> 
  7.      * 修改日期: <br> 
  8.      * @param bitmap 用来构建子集的源位图 
  9.      * @param iconWidth 新位图期望的宽度 
  10.      * @param iconHeight 新位图期望的高度 
  11.      * @param filter 未知 
  12.      * @return Bitmap 一个新的按比例变化的位图。 
  13.      */  
  14.     public static Bitmap createScaledBitmap(Bitmap bitmap, int iconWidth, int iconHeight, boolean filter) {  
  15.         Bitmap bitmap2;  
  16.         try {  
  17.             bitmap2 = Bitmap.createScaledBitmap(bitmap, iconWidth, iconHeight, filter);  
  18.         } catch (OutOfMemoryError localOutOfMemoryError) {  
  19.             gc();  
  20.             bitmap2 = Bitmap.createScaledBitmap(bitmap, iconWidth, iconHeight, filter);  
  21.         }  
  22.         return bitmap2;  
  23.     } 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值