簡體   English   中英

Android:如何讓ImageView填充屏幕

[英]Android: how to get ImageView to fill screen

我不知道如何讓圖像填滿屏幕,嘗試了一切,也許我應該使用一些特殊的布局..?

我正在使用ImageView,但這只占屏幕的70%左右,在底部留下空白......

目前我只是使用LinearLayout並將其背景設置為我的圖像。 雖然這填滿了屏幕,但圖像有輕微的拉伸,這是我不想要的。

任何幫助將不勝感激! :)

我的布局文件的ImageView標簽內的代碼是:

android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:scaleType="centerCrop" 
android:adjustViewBounds="true" 
android:src="@drawable/image" 

//在你的xml Image屬性中

android:scaleType="fitXY"

或//以編程方式使用

imgview.setScaleType(ScaleType.FIT_XY);

注意:這適用於使用android:src =“...”而不是android:background =“...”設置圖像時,默認情況下將背景設置為拉伸並適合視圖。

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="centerCrop"
    android:adjustViewBounds="true"
    android:src="@drawable/image"

只需更改布局寬度和高度,這將適用於'center'和'centercrop'

在Image View xml代碼中使用以下行。

android:scaleType="fitXY"

別忘了刪除

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

來自layoutparams,位於活動的xml頂部。 否則圖像將填滿整個屏幕。

您幾乎可以使用任何布局,只需將背景圖像設置為圖像即可。 然后只需將寬度和高度填充為父級。

或實例如果您只想將圖像設置為主線性布局

    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:orientation="horizontal"
      android:layout_height="fill_parent"
      android:background="@drawable/yourimage">
</LinearLayout>     

暫無
暫無

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

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