【问题标题】:How do I make my ImageView a fixed size regardless of the size of the bitmap无论位图大小如何,如何使我的 ImageView 成为固定大小
【发布时间】:2011-04-16 10:58:57
【问题描述】:

所以我从 Web 服务加载图像,但图像的大小有时比其他图像更小或更大,当我将它们放在 android 的 ListView 中时,可视化看起来很傻。我想修复我的 ImageView 的大小,以便它只显示图像的一部分,如果它大于预设数量。我已经尝试了所有我能想到的设置 setMaxWidth/setMaxHeight,将比例类型设置为 centerCrop,使用 ClipableDrawable 包装我的 BitmapDrawable,使用 Drawable.setBounds() 设置。我尝试过在 XML 中进行设置并以编程方式进行设置,但都没有奏效。我很惊讶设置最大宽度/高度没有做任何事情。下面是我在布局文件中使用 ImageView 定义的 XML:

    <ImageView android:id="@+id/recipeImage"
           android:maxHeight="64px"
           android:maxWidth="64px"
           android:scaleType="centerCrop"
           android:layout_width="wrap_content"
           android:layout_height="fill_parent"
           android:layout_alignParentTop="true"
           android:layout_alignParentBottom="true"
           android:layout_marginRight="6dip"/>

但是,没有任何效果。

【问题讨论】:

    标签: java android bitmap imageview


    【解决方案1】:

    只需删除maxHeightmaxWidth 属性并在layout_widthlayout_height 中适当地输入您的单位。但不要使用 px 单元 - 改用 dp,因为它们与设备无关。

    【讨论】:

    • minHeightminWidth 怎么样?
    【解决方案2】:

    这将使图像适应指定的高度和宽度,而与图像大小无关。

    <ImageView
            android:id="@+id/image5"
            android:layout_width="300dp"
            android:layout_height="200dp"
            android:src="@drawable/image_1"
            android:scaleType="fitXY"/>
    

    【讨论】:

      【解决方案3】:
      Get ImageVIews as facebook posts.    
      Glide.with(context).load(link)
                          .placeholder(R.drawable.aboutlogo)
                          .fitCenter()
                          .diskCacheStrategy(DiskCacheStrategy.ALL)
                          .into(imageView);`
      
              <ImageView
                          android:id="@+id/img1"
                          android:src="@drawable/ic_menu_camera"
                          android:adjustViewBounds="true"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:scaleType="center"/>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-20
        • 2013-12-12
        • 1970-01-01
        相关资源
        最近更新 更多