gpt4 book ai didi

android - 如何在 Android 的 ImageView 中只显示部分图片的宽度?

转载 作者:行者123 更新时间:2023-11-30 03:28:32 26 4
gpt4 key购买 nike

我在 ImageView 中有一个非常宽的图像,因为我将它用作动画背景。如何显示图片以使其高度填满整个父级并且显示宽度与屏幕宽度一样多?

我试着用这段代码做这个:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >

<ImageView
android:id="@+id/background"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/background"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"/>

</RelativeLayout>

但它不起作用。它只是在屏幕内显示整个图片,将其宽度调整为屏幕宽度。我哪里弄错了?

最佳答案

你有没有试过这样的事情:

How to display a part of an image?

或者你可以使用android缩放

 Use android:scaleType="centerInside"

关于android - 如何在 Android 的 ImageView 中只显示部分图片的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17845507/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com