标签:
public static int dip2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { int childLeft = 0; final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View childView = getChildAt(i); if (childView.getVisibility() != View.GONE) { final int childWidth = childView.getMeasuredWidth(); /* Vanzo:zhangshuli on: Wed, 21 Jan 2015 18:12:28 +0000 childView.layout(childLeft, 0, childLeft + childWidth, childView.getMeasuredHeight()); */ int top = (int) mContext.getResources().getDimension(R.dimen.share_item_port_top); childView.layout(childLeft, top, childLeft + childWidth, childView.getMeasuredHeight()); // End of Vanzo: zhangshuli childLeft += childWidth; } } } @Override public View getView(final int position, View convertView, ViewGroup parent) { if (convertView == null) { if (MmsConfig.getIpMessagServiceId(mContext) == IpMessageServiceId.NO_SERVICE) { convertView = LayoutInflater.from(mContext).inflate(R.layout.share_grid_common_item, null); } else { convertView = LayoutInflater.from(mContext).inflate(R.layout.share_grid_item, null); } convertView.setTag(convertView); } else { convertView = (View) convertView.getTag(); } /* Vanzo:zhangshuli on: Wed, 21 Jan 2015 18:16:59 +0000 */ int height = (int) mContext.getResources().getDimension(R.dimen.share_item_port_height); int width = (int) mContext.getResources().getDimension(R.dimen.share_item_port_width); AbsListView.LayoutParams param = new AbsListView.LayoutParams(width, height); convertView.setLayoutParams(param); // End of Vanzo:zhangshuli TextView text = (TextView) convertView.findViewById(R.id.tv_share_name); ImageView img = (ImageView) convertView.findViewById(R.id.iv_share_icon); if (position < mStringArray.length) { text.setText(mStringArray[position]); img.setImageResource(mIconArray[position]); } return convertView; } }
标签:
原文地址:http://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_zj_15012022.html