嘿伙计们,我一直在开发墙纸应用程序,它几乎完成了,但是当我尝试在各种设备上测试它时,Gridview 图像被拉伸或重叠我已经阅读了一些关于支持 MultiScreens 的文档,我认为我应该考虑所有屏幕(尺寸/分辨率/密度),但我不确定如何在我的代码中实现它我的 laout
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/GridView1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:columnWidth="90dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:gravity="center"
android:stretchMode="columnWidth"
android:background="@android:color/black"
>
我的图像适配器
public View getView(int position, View view, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
try {
InputStream is = mContext.getAssets().open(list.get(position));
Bitmap bm = BitmapFactory.decodeStream(is);
imageView.setImageBitmap(bm);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
if (mContext.getResources().getDisplayMetrics().densityDpi > 200) {
imageView.setLayoutParams(new GridView.LayoutParams(mheight/3, v mwidth/3));
}
else{
imageView.setLayoutParams(new GridView.LayoutParams(mheight/3, mwidth/3));
}
} catch (IOException e) {
e.printStackTrace();
}
// TODO Auto-generated method stub
return imageView;
}
我只想在所有手机屏幕上显示 3 列图像如果有人可以指导我某些教程我会很高兴提前谢谢
更新代码
public View getView(int position, View view, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
try {
InputStream is = mContext.getAssets().open(list.get(position));
Bitmap bm = BitmapFactory.decodeStream(is);
imageView.setImageBitmap(bm);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
} catch (IOException e) {
e.printStackTrace();
}
// TODO Auto-generated method stub
return imageView;
}
The layout
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/GridView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="3"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:gravity="center"
android:stretchMode="columnWidth"
android:background="@android:color/black"
>