【发布时间】:2014-07-02 15:46:28
【问题描述】:
我在使用包含 ImageView 的 ListView 时遇到问题,它在平板电脑上可以正常工作,但在我的手机上却不行...
这是预期的输出(在我的平板电脑上):
这是实际输出(在我的手机上):
我尝试使用可绘制对象,它在我的手机上运行良好。 以下是我创建位图并将其绑定到视图的方法:
Bitmap srcBmp = BitmapFactory.decodeResource(rcontext.getResources(), R.drawable.portrait);
Bitmap modBmp = Bitmap.createBitmap(srcBmp,0,0,60,60);
((ImageView) view).setImageBitmap(thebmp);
我的行布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="60px"
android:layout_height="60px"
android:id="@+id/charIcon"
android:src="@drawable/blason" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/charName"/>
</LinearLayout>
我真的不明白为什么会这样...... 我对android很陌生,但这真的很奇怪
编辑:blason 仅在我的可绘制文件夹中,其大小为 60x60 像素
EDIT2:我正在使用这个 Bitmap.createBitmap(srcBmp,0,0,60,60);因为我只需要图像的这一部分(应该显示整个头部)。这是 Portrait.png 的一部分:
【问题讨论】:
-
您正在使用 px。尝试使用 dp。它会更好地扩展。
-
如果您的可绘制文件夹中有图像并且它的尺寸完美,那么为什么不直接使用
imageView.setImageResource(R.drawable.blason);进行设置 -
dp/px 似乎不是这里的问题。在我的平板电脑上显示整个头部,而不是在手机上,无论我为 ImageView 使用什么尺寸
-
@Shivam_Verma : blason 资源只是一个默认图像,以防我以后找不到要显示的好角色