gpt4 book ai didi

android - ImageView 不拉伸(stretch)(Android)?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:50:16 27 4
gpt4 key购买 nike

我在 RelativeLayout 中有一个 ImageView。 ImageView 的源是一个 .png 文件。问题是当在具有不同分辨率的设备上测试时,android 不会放大或缩小图像。我在 android 文档中读到 android 会自动向上或向下缩放图像以填满屏幕,但这并没有发生。可能是什么问题呢?我是 android 的新手,如果这个问题很愚蠢,我很抱歉,我搜索了很多但找不到解决方案。

编辑:XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>

<ImageView
android:id="@+id/imageview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_centerInParent="true"
android:clickable="false"
android:scaleType="fitXY"
android:contentDescription="@string/p"

android:src="@drawable/example" />
</RelativeLayout>

编辑 2:我需要拉伸(stretch)的 XML 布局:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:gravity="center">

<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/imageView1"
android:clickable="false"

android:contentDescription="@string/p"

android:src="@drawable/volbar" />



<ImageView

android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:layout_alignParentLeft="true"
android:contentDescription="@string/p"

android:src="@drawable/head" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="33dp"
android:layout_marginRight="19dp"
android:text="@string/press_to_update" />

<ImageView
android:id="@+id/imageView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/imageView2"
android:clickable="false"
android:contentDescription="@string/p"

android:src="@drawable/frag11"
/>

<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"

android:layout_below="@+id/imageView9"
android:clickable="false"
android:contentDescription="@string/p"

android:src="@drawable/base" />
</RelativeLayout>

最佳答案

在布局中使用android:scaleType="fitXY"

编辑

如果你想让图像占据整个屏幕然后使用

    android:layout_width="match_parent"
android:layout_height="match_parent"

关于android - ImageView 不拉伸(stretch)(Android)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16108517/

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