-1

我有一個圖像視圖變成Relativelayout,我從圖庫中挑選圖像..問題是Imageview高度太大,相對佈局父級高度變得與高度Imageview相同,我需要從圖庫中選擇圖像並將其精確顯示到相對佈局中。android imageview進入相對佈局設置高度

我下面的代碼

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <ImageView 
      android:id="@+id/image_view" 
      android:layout_margin="5dp" 
      android:layout_alignParentEnd="true" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:scaleType="fitStart" 
      android:adjustViewBounds="true" 
      android:src="@drawable/crayon" /> 

</RelativeLayout> 
+0

你想要什麼到底是什麼? – tahsinRupam

+0

嘗試使用'android:scaleType =「fitXY」'.. – rafsanahmad007

+0

我想讓imageview高度完全適合相對佈局高度,而不是更大 – Malo

回答

1

試試這個:刪除android:layout_alignParentEnd="true"

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 


    <ImageView 
     android:id="@+id/image_view" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:layout_margin="5dp" 
     android:adjustViewBounds="true" 
     android:scaleType="fitXY" 
     android:src="@drawable/calender" /> 
</RelativeLayout> 
1
<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ImageView 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:src="@drawable/bgg" 
    android:id="@+id/imageView8" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="71dp" /> 
</RelativeLayout> 
1

我也越來越相同的問題:試試這個

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white"> 

    <ImageView 
     android:id="@+id/flag" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="false" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     android:adjustViewBounds="true" 
     android:background="@color/white" 
     android:foregroundGravity="center" 
     android:scaleType="fitXY" 
     android:src="@drawable/guide3" /> 

</RelativeLayout>