设置布局文件的图片按合适的大小显示

今天在写代码的时候写了这样的一个布局,但是发现结果不是我想要的

布局代码:

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_gravity="center_horizontal"
    android:gravity="center_horizontal">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/house"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/kaisuoma"/>
    <TextView
        android:id="@+id/kaisuoma"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="0222"
        android:textSize="60dp"
       />
</LinearLayout>

 

这个布局本来是上面一张图片,下面两行文字的,但是运行结果却变成了这个样子

 

 

后来找到了更改方法,就是在ImageView中添加android:adjustViewBounds属性ImageView的android:adjustViewBounds属性为是否保持原图的长宽比

更改后的代码
<ImageView
    android:adjustViewBounds="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/house"/>

 

结果就好了(界面有点丑,大家不要介意

end 


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值