簡體   English   中英

圖像未在布局中占據完整的ImageView

[英]Image not occupying full ImageView in layout

我創建了一個具有默認圖像的畫廊,當單擊時,其中一個被單擊並顯示在其他活動中,但是我的問題是,在加載圖像時它沒有占據整個屏幕。

這是xml-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drag_activity_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DragActivity" >

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

</RelativeLayout>

然后使用以下代碼將圖像從活動加載到此imageview。

Intent intent = getIntent();
        int ImageId = intent.getIntExtra("drawableId", 0);

        imgView = (ImageView) findViewById(R.id.imageViewEdit);
        imgView.setImageResource(ImageId);

在此處輸入圖片說明

是圖像占據整個圖像視圖的一種方式。 專家請幫助我,這是Android的新手。 提前致謝。

更改

imgView.setImageResource(ImageId);

imgView.setBackgroundResource(ImageId);

在ImageView上設置android:scaleType屬性,諸如centerCrop之類的內容應填滿屏幕

更改ImageViewScaleType 將此添加到您的ImageView標簽:

android:scaleType = "fitCenter"

使用imageView.setBackground()屬性

請參閱此鏈接https://developer.android.com/reference/android/widget/ImageView.ScaleType.html

android:scaleType="FIT_XY"到您的ImageView。

暫無
暫無

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

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