簡體   English   中英

在不改變寬高比的情況下將背景圖像填充到屏幕

[英]Filling a background image to screen without changing aspect ratio

我想將圖像顯示為我的活動的背景,但是想要在不改變圖像寬高比的情況下將其填充到屏幕上(類似這樣 )。

我嘗試縮放圖像,但這似乎不起作用(因為我使用圖像作為背景,而不是在圖像視圖中定義它,或者似乎是問題)。

我該怎么做呢? 我甚至嘗試在自己的xml文件中定義背景圖像,但仍然無效。

如果您使用RelativeLayout,您可以放置​​一個ImageView,而不是填充所有布局,並將其余部分放在上面。 像這樣的東西:

<?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" >

<ImageView
    android:id="@+id/background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="centerCrop"
    android:src="@drawable/background" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    // Your full layout
</LinearLayout>

</RelativeLayout>

AFAIK唯一的解決方案是你提到的ImageView。 為什么它不適合你? 您還可以使用Bitmap.createBitmap()方法調整位圖大小,使其達到所需的大小。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM