【问题标题】:standard text and image size in android listviewandroid listview中的标准文本和图像大小
【发布时间】:2011-02-19 19:08:24
【问题描述】:

嗨 我正在从 Web 读取 XML 并将它们显示在列表视图中。 xml 包含一个图像位置,因此我将图像与文本一起显示。 图片尺寸为 48*48 像素,建议 here。但是当我在实际设备中看到列表视图时,图像看起来非常小。关于如何使该图像有点大的任何想法?有没有标准的图片和文字大小?? 这是我的布局:-

<ImageView
    android:id="@+id/logo"
    android:layout_gravity="left"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    />
<TextView 
  android:id="@+id/name"
  android:textSize="16sp" 
  android:textStyle="bold" 
  android:textColor="#2B2B2B" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"
  android:paddingLeft="5dp"
  android:layout_toRightOf="@id/logo"

/>

【问题讨论】:

    标签: android listview android-layout


    【解决方案1】:

    使用 dip 代替 px。当你使用 dip 时,它在不同的屏幕上显得更可调和更好。

    【讨论】:

    • 我没有在任何地方使用 px。我是吗?实际图像尺寸为 48*48 像素。你的意思是创建 48*48 dp 的图像吗?
    • 如果你设置 android:layout_width="32dip" android:layout_height="32dip" 它将起作用。如果图像看起来仍然紧凑,您可以增加我在此处所说的倾角
    • 谢谢老兄。这是我一直在寻找的东西。对我有用。
    【解决方案2】:

    像这样使用 ImageView:

    根据自己的喜好修改宽度和高度值,但使用倾角测量。使用 scaleType 属性,您可以告诉框架拉伸您的图像。

    【讨论】:

      【解决方案3】:

      尝试添加

      android:scaleType="center"
      

      到您的 ImageView XML。这不会缩放您的图像,而是在您的视图中居中。

      【讨论】:

        【解决方案4】:

        在 Android 上按像素声明布局大小是一种不好的做法。这个页面直接来自谷歌关于这个主题:http://developer.android.com/guide/practices/screens_support.html我会做这样的事情

        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        

        看看它的样子。在完成之前不要忘记在多种屏幕尺寸上进行测试。您可以通过为模拟器创建不同的 AVD 来做到这一点。

        如果您真的愿意,您可以使用像素,但请记住,它在不同的设备上看起来会有所不同。

        android:layout_height="96dip"
        android:layout_width="fill_parent"
        

        【讨论】:

        • 此时使用 android:layout_height="96dip" 给了我一个很好的结果。但我仍然要在不同的设备上测试它。谢谢。
        猜你喜欢
        • 2012-03-11
        • 2015-07-14
        • 1970-01-01
        • 2015-02-01
        • 1970-01-01
        • 2011-05-29
        • 2016-10-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多