Android-GridView填充问题
|
我正在将图像加载到
GridView
的应用程序上工作...我现在的问题是
当即时通讯使用ѭ1时,它对HTC Hero的工作效果很好,但如果使用Motorola Droid,它们彼此重叠...
如何使所有移动通用的填充...
这是我的代码。
package com.android.sampleDesign1;
import android.content.Context;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;
public class TicTacToeAdapter extends BaseAdapter {
public ImageView imageView;
private Context mContext;
private Integer mThumbIds = R.drawable.images;
private Integer image;
public TicTacToeAdapter(Context c) {
mContext = c;
}
public int getCount() {
return 9;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
image = mThumbIds;
if (convertView == null) {
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageResource(image);
imageView.setPadding(10,10,10,10);
} else {
imageView = (ImageView) convertView;
imageView.setImageResource(image);
}
return imageView;
}
}
我也曾尝试使用
int w = gridView.getWidth();
int myViewWidth = Math.round(W * .12f);
而且我尝试了
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
lp.setMargins(left, top, right, bottom);
imageView.setLayoutParams(lp);
所以还有其他方法可以做..还是我在任何地方都错了..
帮帮我..
提前致谢。
没有找到相关结果
已邀请:
1 个回复
姬第柔炒
中定义填充,您需要在
(与密度无关的像素)中定义填充,然后在运行时将
转换为
。 所以你需要做类似的事情
您在构造函数中获得的
会根据运行应用程序的设备的屏幕密度而有所不同。 (注意:
和
是同一件事)