gpt4 book ai didi

java - android适合图像以填充整个布局

转载 作者:行者123 更新时间:2023-11-29 05:57:01 26 4
gpt4 key购买 nike

我有一张图像,它的分辨率适合我的测试设备的整个屏幕。当使用其他屏幕尺寸进行测试时,图像仅适合宽度或高度并留下空白空间,因为它始终按比例缩放。如果比例发生变化,我如何设置图像以适应全屏?例如,如果我的设备屏幕是 3/4,图像将在 3/4 显示器上正确缩放,与其分辨率无关。但是,对于 16/9 将不适合全屏。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="@color/blueish"
android:layout_height="fill_parent">
<ImageView
android:src="@drawable/splashandroid"
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ImageView>


</LinearLayout>

还尝试了 wrap_content 作为图像布局宽度

最佳答案

在你的 ImageView 中添加这个,android:scaleType="fitXY" 或者你可以在你的 Activity 中使用这个意味着 imgview.setScaleType(ScaleType.FIT_XY);

你可以试试这个,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="@color/blueish"
android:layout_height="fill_parent">
<ImageView
android:src="@drawable/splashandroid"
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"/>

</LinearLayout>

关于java - android适合图像以填充整个布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11686692/

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