【问题标题】:Scale image in ImageView to width of the parent and scale in height accordingly将 ImageView 中的图像缩放到父级的宽度并相应地缩放高度
【发布时间】:2014-12-31 09:42:25
【问题描述】:

将所有内容放在一个文件中以使其更清晰,连同代码和结果:

【问题讨论】:

  • 它不起作用...检查更新
  • 因为您的要求不是标准 scaleType 使用 scaleType="matrix" 并计算矩阵以满足您的需求

标签: android xml image imageview scale


【解决方案1】:

试试这个..

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="false"
    android:background="@drawable/image1"/>

编辑:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="2"
    android:gravity="right" >

   <ImageView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:adjustViewBounds="false"
    android:layout_gravity="right"
    android:layout_weight="1"
    android:background="@drawable/ic_launcher"/>

</LinearLayout>

edit2

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="right"
    android:orientation="vertical"
    android:weightSum="10" >

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@drawable/ic_launcher" />


</LinearLayout>

【讨论】:

  • 它可以工作,但就像在高度上使用 dp 一样,只是这次我取了整个高度的 1/10。我还需要一个相对布局,因为我需要稍后在另一个上绘制多个图像
  • 你也可以使用线性布局进行设计。通过使用嵌套线性布局设置方向 n。
  • 好的,谢谢你的帮助,我接受你的努力的答案:) 太糟糕了,我无法得到我想要的
  • 很高兴能帮助你,伙计..如果工作再次抓住我,请尝试线性布局..我会帮助你解决问题。 :) 新年快乐..
【解决方案2】:

将图像视图的宽度设置为“fill_parent”。 它也解决了你的问题。

【讨论】:

  • 查看当前的代码和图片... 不知道为什么达不到我想要的,也许你能想办法
  • 你用过重量吗??如果您使用的是线性布局,请记住使用权重这一点。
猜你喜欢
  • 2018-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-27
  • 2013-11-05
  • 1970-01-01
相关资源
最近更新 更多