android - 图像不适合 QuickContactBadge

标签 android android-layout android-listview

我已经创建了一个联系人号码 ListView ,列表项包含 QuickContactBadgeTextView 现在,每当我尝试将图像加载到 QuickContactBadge 时,它​​都无法获取适合 QuickContactBadge 框架,同时 QuickBadgeContact 本身也会缩小。

现在我有这个

enter image description here

我想要实现的是

enter image description here

所以不仅是图像,甚至我也在尝试使 QuickContactBadge 具有正常尺寸

这是我正在使用的代码

    Uri contactUri = Uri.withAppendedPath(
                            ContactsContract.Contacts.CONTENT_URI, 
                             String.valueOf(contactId));

    InputStream input = ContactsContract.Contacts.openContactPhotoInputStream
                            (
                            getContentResolver(), contactUri
                            );


 cache.photoView.setImageBitmap(BitmapFactory.decodeStream(input));

我的列表项布局

<QuickContactBadge
        android:id="@+id/badge"
        android:layout_marginLeft="2dip"
        android:layout_marginRight="14dip"
        android:layout_marginTop="4dip"
        android:layout_marginBottom="3dip"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_height= "wrap_content"
        android:layout_width= "wrap_content"
        android:src="@drawable/ic_contact_picture"
        style="?android:attr/quickContactBadgeStyleWindowSmall" />

    <TextView
        android:id="@+id/name"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:paddingLeft="2dip"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@id/badge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

最佳答案

//尝试对布局高度和宽度进行硬编码

android:layout_height= "50dp" android:layout_width= "50dp"

//确保使用 dp/dip 填充适合您的所有屏幕分辨率

假设您的 mdpi 的 50dp 与 50px 相同

mdpi 50*160/160=50px
hdpi 50*240/160=75px
xhdpi 50*320/160=100px

关于android - 图像不适合 QuickContactBadge,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9498809/

相关文章:

带有 Dagger 的 Android Gradle 构建问题

java - 避免 Android 中绘制/布局操作期间出现对象分配错误

android - Fragments 文档中的莎士比亚是什么?

android - 为什么类扩展 intentservice 需要空构造函数?

android - 如何在不填充孔的情况下填充包含孔的 Android 路径?

android - Ionic 3 - native 文件问题

java - String.xml 包含太多项目,速度太慢

android - 没有标题的自定义对话框弄乱了我的布局

android - 如何检测用户何时滚动到 ListView 顶部并通过 ListView 传递触摸(如果是)?

java - 单击 ListView 时如何启用/禁用 ListView 中的复选框?