android– 布局:如何使图像按比例改变其宽度和高度?

android– 布局:如何使图像按比例改变其宽度和高度?,第1张

概述我有这样的布局:<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apkes/android"xmlns:tools="http://schemas.android.comools"android:layout_width="wrap_con

我有这样的布局:

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools="http://schemas.androID.com/tools"androID:layout_wIDth="wrap_content"androID:layout_height="wrap_content"androID:orIEntation="horizontal"><TextVIEw    androID:ID="@+ID/Title"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_alignParentleft="true"    androID:layout_centerVertical="true"    androID:layout_toleftOf="@+ID/my_image"    androID:ellipsize="end"    androID:singleline="true"    androID:text="Some text"    androID:textAppearance="?androID:attr/textAppearanceMedium" /><ImageVIEw    androID:ID="@+ID/my_image"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_aligntop="@+ID/Title"    androID:layout_alignBottom="@+ID/Title"    androID:layout_alignParentRight="true"    androID:layout_centerVertical="true"    androID:adjustVIEwBounds="true"    androID:src="@drawable/my_bitmap_image" />

这种布局几乎可以满足我的需要:它使图像视图高度与文本视图相同.拉伸的图像图形内容也保持纵横比.

但是,图像视图的宽度不会改变!结果,我在文本和图像视图之间有很大的差距!作为时间解决方案,我重写了VIEw#onLayout.

问题:如何在xml布局中更改图像宽度?

更新:

这是我需要的最终布局(发短信几张图片).
查看第一个图像:它的宽度应该与缩放图像完全相同,没有填充和边距:

解决方法:

对于imageVIEw,您可以将图像添加到线性布局并提供权重属性.例如,如果您有3个图像,则将线性布局权重指定为3,然后对于每个图像,您将权重指定为1.这样,对于所有图像,它将均匀对齐,宽度相等.使线性方向成为横向希望,所以你明白我的观点.

    <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    androID:orIEntation="horizontal"     androID:weightSum="3"     >   <ImageVIEw androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:orIEntation="horizontal"     androID:layout_weight ="1" />    <ImageVIEw androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:orIEntation="horizontal"     androID:layout_weight ="1" />    <ImageVIEw androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:orIEntation="horizontal"     androID:layout_weight ="1" />     </linearLayout>
总结

以上是内存溢出为你收集整理的android – 布局:如何使图像按比例改变其宽度和高度?全部内容,希望文章能够帮你解决android – 布局:如何使图像按比例改变其宽度和高度?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1112990.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存