图文:WRAP_CONTENT,但MAX_WIDTH =布局宽度 [英] Photo: wrap_content, but max_width = layout width

查看:136
本文介绍了图文:WRAP_CONTENT,但MAX_WIDTH =布局宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正常的阅读文章类型的页面顶部有一个单一的大照片。

我想它想:


  • 不是规模比源imgae较大

  • 不大于屏幕

  • 不是疯了长垂直

  • 侧的事情,我已经有工作

    • 边界(通过填充),中心裁剪(宁愿顶作物,但似乎没有利用)


我遇到的主要问题是 - 我可以把它FILL_PARENT(即全宽)OR WRAP_CONTENT(即大到原始图像)。并没有什么到目前为止,我已经做可以使图像是正常大小(即保持距离扩大)。

有没有一种规范对这种事情?我敢肯定有某种甜蜜点或此的作品属性的组合 - 我无法找到他们。

我目前的尝试:

 < ImageView的
            机器人:ID =@ + ID / article_photo
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:背景=@彩色/ super_light_gray
            机器人:scaleType =centerCrop
            机器人:contentDescription =@字符串/ articlePhoto
            机器人:cropToPadding =真
            机器人:layout_marginBottom =20dp
            机器人:填充=1DP/>


解决方案

您可以写一些code的活动来获得图像的大小和显示尺寸。

如果图像大小超过显示尺寸设置宽度显示,如果没有设置图像大小。如果你想成为看上你可以找到x和y的比例和规模也垂直

I have a normal "read an article" type page with a single large photo at the top.

I'd like it to:

  • not scale larger than the source imgae
  • not be larger than the screen
  • not be CRAZY long vertically
  • side things I already have working
    • border (via padding), center crop (would rather top crop, but seems not avail)

The main issue I'm having is - I can either have it fill_parent (ie full width) OR wrap_content (ie as large as the original image). And nothing I have done so far allows the image to be normal size (ie keep from enlarging).

Is there a "norm" for this kind of thing? I'm sure there's some kind of sweet spot or combination of attributes for this that works - I just can't find them.

My current attempt:

        <ImageView
            android:id="@+id/article_photo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/super_light_gray"
            android:scaleType="centerCrop"
            android:contentDescription="@string/articlePhoto"
            android:cropToPadding="true"
            android:layout_marginBottom="20dp"
            android:padding="1dp"/>

解决方案

You can write some code in the Activity to get the image size and display size.

If the image size exceeds display size set width to display, if not set to image size. If you want to be fancy you can find the ratio between the x and y and scale vertically also.

这篇关于图文:WRAP_CONTENT,但MAX_WIDTH =布局宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆