Buenas tardes;
我试图在 ScrollView 中放置几个图像,我遇到的问题是它会在图像上方和下方生成一个空间;我目前正在添加两个图像。
当我以下列方式使用图像标签时,它会在每个图像的上方和下方生成空格:
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/calendario1"
android:contentDescription="@string/pregrado"/>
我显然已经通过以下更改修复了它:android:layout_height="650dp"
<ImageView
android:layout_width="match_parent"
android:layout_height="650dp"
android:src="@drawable/calendario1"
android:contentDescription="@string/pregrado"/>
模拟时使用这个宽度和高度可以很好地向我展示图像,但是有了这些特性,图像是否会按比例显示在不同的屏幕上?这是我不知道的;此外,它向我显示一个错误:
这是此布局的完整代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff"
tools:context="com.tecnologias.uniagustapp.fragmentos.Fragment_Calendario">
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center"
android:text="@string/calendario_acad_mico_i_2018"
android:textColor="#ffffff"
android:background="#130f54"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="15dp"
android:gravity="center"
android:background="#ffffff"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="match_parent"
android:layout_height="650dp"
android:src="@drawable/calendario1" android:contentDescription="@string/pregrado"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="650dp"
android:src="@drawable/calendario2" android:contentDescription="@string/posgrado"/>
</LinearLayout>
</ScrollView>
尝试在 ImageView 上将 adjustViewBounds 属性更改为 true,它适用于将图像调整为容器。
为了使您的图像适应设备,我通常将宽度保留在 match_parent 中,将高度保留在 wrap_content 中,我还读过要在 Android 中使用本地图像最好以 .png 格式使用它们