[英](android) ImageView gets bigger when i set background
單擊“ btn_report_addImage1”后,應用程序將調用相機功能進行拍照。 然后,該按鈕消失了,並出現了內部relativeLayout來顯示我拍攝的照片,並在該照片的右上角顯示移除按鈕。
問題是:我將圖像視圖的大小設置為65dp的寬度和高度。 但是,當圖片顯示在imageView上時,圖片會變得比以前更大。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="65dp"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="65dp"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_report_addImage1"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<RelativeLayout
android:id="@+id/layout_report_image1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" >
<ImageView
android:id="@+id/image_report_image1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"/>
<Button
android:id="@+id/btn_report_removeImage1"
android:layout_width="35dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:text="-"
android:textSize="5dp"
/>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="65dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp">
<Button
android:id="@+id/btn_report_addImage2"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="@+id/layout_report_image2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<ImageView
android:id="@+id/image_report_image2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"/>
<Button
android:id="@+id/btn_report_removeImage2"
android:layout_width="35dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</RelativeLayout>
您已將scaleType指定為fitXY。 這就是原因。 android:scaleType="fitXY"
在我們稱為fitXY
的Axis中對圖像進行縮放以適合視圖,如果您已經定義了Image的l*b
,請刪除ScaleType = fitXY
:
<ImageView
android:id="@+id/image_report_image1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
// scaleType removed
您可以將ImageView scaleType設置為“ centerCrop”。
<ImageView
android:id="@+id/image_report_image1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
嘗試在src中實用地添加圖像。 因此您可以獲得適當的圖像尺寸並顯示正確。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.