现在的位置: 首页 > 综合 > 正文

分辨率适配的方法

2013年08月13日 ⁄ 综合 ⁄ 共 3740字 ⁄ 字号 评论关闭

它解决了分辨率跟密集度的关系,但是也引来一个问题,就是布局会因为图片资源小而失真,所以这也需要美工的同志多多配合的,贴代码:

第一步,先创建一个view信息的javabean类:

  1. package com.zte.layout.adapter;

  2. import android.view.View;

  3. /**
  4. * 存储View信息的JavaBean类

  5. * @author 

  6. */
  7. public class LayoutInformation
  8. {
  9.         /**
  10.          * View的对象
  11.          */
  12.         private View view;

  13.         /**
  14.          * View的宽度
  15.          */
  16.         private double viewWidth;

  17.         /**
  18.          * View的高度
  19.          */
  20.         private double viewHeight;

  21.         /**
  22.          * View距左边的距离,即marginLeft
  23.          */
  24.         private double viewMarginLeft;

  25.         /**
  26.          * View距顶部的距离,即MarginTop;
  27.          */
  28.         private double viewMarginTop;
  29.         
  30.         /**
  31.          * 父类布局的类型为相对布局
  32.          */
  33.         public static int R=-1;
  34.         
  35.         /**
  36.          * 父类布局的类型为线性布局
  37.          */
  38.         public static int L=-2;
  39.         
  40.         /**
  41.          * 此View的父类布局的类型
  42.          */
  43.         private int parentLayoutType;

  44.         /**
  45.          * 存储View信息的JavaBean类
  46.          * 
  47.          * @param view
  48.          *            View的对象
  49.          * @param viewWidth
  50.          *            View的宽
  51.          * @param viewHeight
  52.          *            View的高
  53.          * @param viewMarginLeft
  54.          *            View距左边的距离
  55.          * @param viewMargdoubleop
  56.          *            View距上部的距离
  57.          * @param parentLayoutType
  58.          *            父类布局的类型,LayoutInformation.R
  59.          *            (表示相对布局)或者LayoutInformation.L(表示线性布局)
  60.          */
  61.         public LayoutInformation(View view, double viewWidth, double viewHeight,
  62.                         double viewMarginLeft, double viewMarginTop, int parentLayoutType)
  63.         {

  64.                 this.view = view;
  65.                 this.viewWidth = viewWidth;
  66.                 this.viewHeight = viewHeight;
  67.                 this.viewMarginLeft = viewMarginLeft;
  68.                 this.viewMarginTop = viewMarginTop;
  69.                 this.parentLayoutType=parentLayoutType;
  70.         }

  71.         /**
  72.          * 获取View的对象
  73.          * 
  74.          * [url=home.php?mod=space&uid=7300]@return[/url] View对象
  75.          */
  76.         public View getView()
  77.         {
  78.                 return view;
  79.         }

  80.         /**
  81.          * 设置View的对象
  82.          */
  83.         public void setView(View view)
  84.         {
  85.                 this.view = view;
  86.         }

  87.         /**
  88.          * 获取View的宽度
  89.          * 
  90.          * @return View的宽度,double型
  91.          */
  92.         public double getViewWidth()
  93.         {
  94.                 return viewWidth;
  95.         }

  96.         /**
  97.          * 设置View的宽度,double型
  98.          * 
  99.          * @param viewWidth
  100.          */
  101.         public void setViewWidth(double viewWidth)
  102.         {
  103.                 this.viewWidth = viewWidth;
  104.         }

  105.         /**
  106.          * 获取View的高度
  107.          * 
  108.          * @return View的高度,double型
  109.          */
  110.         public double getViewHeight()
  111.         {
  112.                 return viewHeight;
  113.         }

  114.         /**
  115.          * 设置View的高度,double型
  116.          * 
  117.          * @param viewHeight
  118.          */
  119.         public void setViewHeight(double viewHeight)
  120.         {
  121.                 this.viewHeight = viewHeight;
  122.         }

  123.         /**
  124.          * 获取View距离左边的距离
  125.          * 
  126.          * @return View距离左边的距离,double型
  127.          */
  128.         public double getViewMarginLeft()
  129.         {
  130.                 return viewMarginLeft;
  131.         }

  132.         /**
  133.          * 设置View距离左边的距离,double型
  134.          * 
  135.          * @param viewMarginLeft
  136.          */
  137.         public void setViewMarginLeft(double viewMarginLeft)
  138.         {
  139.                 this.viewMarginLeft = viewMarginLeft;
  140.         }

  141.         /**
  142.          * 获取View距离上部的距离
  143.          * 
  144.          * @return View距离上部的距离,double型
  145.          */
  146.         public double getViewMarginTop()
  147.         {
  148.                 return viewMarginTop;
  149.         }

  150.         /**
  151.          * 设置View距离上部的距离,double型
  152.          * 
  153.          * @param viewMargdoubleop
  154.          */
  155.         public void setViewMarginTop(double viewMarginTop)
  156.         {
  157.                 this.viewMarginTop = viewMarginTop;
  158.         }
  159.         
  160.         /**
  161.          * 获取父类布局的类型
  162.          * @return parentLayoutType,int型
  163.          */
  164.         public int getParentLayoutType()
  165.         {
  166.                 return parentLayoutType;
  167.         }

  168.         /**
  169.          * 设置父类布局的类型
  170.          * @param parentLayoutType
  171.          */
  172.         public void setParentLayoutType(int parentLayoutType)
  173.         {
  174.                 this.parentLayoutType = parentLayoutType;
  175.         }

  176. }
  1. package com.zte.layout.adapter;

  2. import android.view.View;

  3. /**
  4. * 存储View信息的JavaBean类

  5. * @author 

  6. */
  7. public class LayoutInformation
  8. {
  9.         /**
  10.          * View的对象
  11.          */
  12.         private View view;

  13.         /**
  14.          * View的宽度
  15.          */
  16.         private double viewWidth;

  17.         /**
  18.          * View的高度

抱歉!评论已关闭.