今天在写代码的时候写了这样的一个布局,但是发现结果不是我想要的
布局代码:
<?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"/>
结果就好了(界面有点丑,大家不要介意)