它解决了分辨率跟密集度的关系,但是也引来一个问题,就是布局会因为图片资源小而失真,所以这也需要美工的同志多多配合的,贴代码:
第一步,先创建一个view信息的javabean类:
-
package com.zte.layout.adapter;
-
-
import android.view.View;
-
-
/**
-
* 存储View信息的JavaBean类
-
*
-
* @author
-
*
-
*/
-
public class LayoutInformation
-
{
-
/**
-
* View的对象
-
*/
-
private View view;
-
-
/**
-
* View的宽度
-
*/
-
private double viewWidth;
-
-
/**
-
* View的高度
-
*/
-
private double viewHeight;
-
-
/**
-
* View距左边的距离,即marginLeft
-
*/
-
private double viewMarginLeft;
-
-
/**
-
* View距顶部的距离,即MarginTop;
-
*/
-
private double viewMarginTop;
-
-
/**
-
* 父类布局的类型为相对布局
-
*/
-
public static int R=-1;
-
-
/**
-
* 父类布局的类型为线性布局
-
*/
-
public static int L=-2;
-
-
/**
-
* 此View的父类布局的类型
-
*/
-
private int parentLayoutType;
-
-
/**
-
* 存储View信息的JavaBean类
-
*
-
* @param view
-
* View的对象
-
* @param viewWidth
-
* View的宽
-
* @param viewHeight
-
* View的高
-
* @param viewMarginLeft
-
* View距左边的距离
-
* @param viewMargdoubleop
-
* View距上部的距离
-
* @param parentLayoutType
-
* 父类布局的类型,LayoutInformation.R
-
* (表示相对布局)或者LayoutInformation.L(表示线性布局)
-
*/
-
public LayoutInformation(View view, double viewWidth, double viewHeight,
-
double viewMarginLeft, double viewMarginTop, int parentLayoutType)
-
{
-
-
this.view = view;
-
this.viewWidth = viewWidth;
-
this.viewHeight = viewHeight;
-
this.viewMarginLeft = viewMarginLeft;
-
this.viewMarginTop = viewMarginTop;
-
this.parentLayoutType=parentLayoutType;
-
}
-
-
/**
-
* 获取View的对象
-
*
-
* [url=home.php?mod=space&uid=7300]@return[/url] View对象
-
*/
-
public View getView()
-
{
-
return view;
-
}
-
-
/**
-
* 设置View的对象
-
*/
-
public void setView(View view)
-
{
-
this.view = view;
-
}
-
-
/**
-
* 获取View的宽度
-
*
-
* @return View的宽度,double型
-
*/
-
public double getViewWidth()
-
{
-
return viewWidth;
-
}
-
-
/**
-
* 设置View的宽度,double型
-
*
-
* @param viewWidth
-
*/
-
public void setViewWidth(double viewWidth)
-
{
-
this.viewWidth = viewWidth;
-
}
-
-
/**
-
* 获取View的高度
-
*
-
* @return View的高度,double型
-
*/
-
public double getViewHeight()
-
{
-
return viewHeight;
-
}
-
-
/**
-
* 设置View的高度,double型
-
*
-
* @param viewHeight
-
*/
-
public void setViewHeight(double viewHeight)
-
{
-
this.viewHeight = viewHeight;
-
}
-
-
/**
-
* 获取View距离左边的距离
-
*
-
* @return View距离左边的距离,double型
-
*/
-
public double getViewMarginLeft()
-
{
-
return viewMarginLeft;
-
}
-
-
/**
-
* 设置View距离左边的距离,double型
-
*
-
* @param viewMarginLeft
-
*/
-
public void setViewMarginLeft(double viewMarginLeft)
-
{
-
this.viewMarginLeft = viewMarginLeft;
-
}
-
-
/**
-
* 获取View距离上部的距离
-
*
-
* @return View距离上部的距离,double型
-
*/
-
public double getViewMarginTop()
-
{
-
return viewMarginTop;
-
}
-
-
/**
-
* 设置View距离上部的距离,double型
-
*
-
* @param viewMargdoubleop
-
*/
-
public void setViewMarginTop(double viewMarginTop)
-
{
-
this.viewMarginTop = viewMarginTop;
-
}
-
-
/**
-
* 获取父类布局的类型
-
* @return parentLayoutType,int型
-
*/
-
public int getParentLayoutType()
-
{
-
return parentLayoutType;
-
}
-
-
/**
-
* 设置父类布局的类型
-
* @param parentLayoutType
-
*/
-
public void setParentLayoutType(int parentLayoutType)
-
{
-
this.parentLayoutType = parentLayoutType;
-
}
-
-
}
-
package com.zte.layout.adapter;
-
-
import android.view.View;
-
-
/**
-
* 存储View信息的JavaBean类
-
*
-
* @author
-
*
-
*/
-
public class LayoutInformation
-
{
-
/**
-
* View的对象
-
*/
-
private View view;
-
-
/**
-
* View的宽度
-
*/
-
private double viewWidth;
-
-
/**
-
* View的高度