我是新手Android开发者,一切都进行得很顺利,直到我需要处理布局的时候。
我想要的布局如下:
图片应该正确缩放并保持其比例。
因此,我尝试使用以下XML代码,但它并不按照我想要的方式工作。 图片保持其比例,但是当垂直时,左右两侧超出了屏幕,并在水平时从上部和下部裁剪:
因此,我尝试使用以下XML代码,但它并不按照我想要的方式工作。 图片保持其比例,但是当垂直时,左右两侧超出了屏幕,并在水平时从上部和下部裁剪:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:background="@color/background">
<ImageView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:src="@drawable/logo"
android:gravity="center"
android:scaleType="centerCrop"
android:contentDescription="@string/app_logo"
android:layout_weight="2.5" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:gravity="center">
<Button
android:id="@+id/id1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:text="@string/text1"
android:textSize="40sp"
/>
<Button
android:id="@+id/id2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:text="@string/text2"
/>
<Button
android:id="@+id/id3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_gravity="center"
android:text="@string/text3" />
</LinearLayout>
</LinearLayout>
我搜索了很多但是就是找不到我想要的内容。请帮忙!