How to Scale images to imageview perfectly with fixed width and height without distorting the image in Android -


iam creating app access images gallery or camera. have imageview 280/280dp dimension. how scale images camera/gallery(which bigger images) below imageview having fixed width , height without distorting image in android:

<imageview     android:layout_width="280dp"     android:layout_height="280dp"     android:id="@+id/mainimage"     android:background="@drawable/profile_settings_main_image"     android:layout_margintop="19dp"     android:layout_below="@+id/container_toolbar"     android:layout_centerhorizontal="true"     android:focusable="false"     android:adjustviewbounds="true"     /> 

activity_main.xml(full layout)

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"  tools:context="in.abc.activity.profilesettings" android:background="#93bfb6">  <linearlayout     android:id="@+id/container_toolbar"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="vertical">      <include         android:id="@+id/toolbar"         layout="@layout/toolbar" />    </linearlayout>   <textview android:layout_width="230dp"     android:layout_height="50dp"     android:textsize="22sp"     android:background="@drawable/profile_settings_name"     android:id="@+id/nameview"     android:textcolor="#000000"     android:layout_margintop="20dp"     android:layout_below="@+id/mainimage"     android:layout_alignleft="@+id/mainimage"     android:layout_alignstart="@+id/mainimage"     android:layout_marginright="1dp"     android:gravity="center"/>  <imageview     android:layout_width="280dp"     android:layout_height="280dp"     android:id="@+id/mainimage"     android:background="@drawable/profile_settings_main_image"     android:layout_margintop="19dp"     android:layout_below="@+id/container_toolbar"     android:layout_centerhorizontal="true"     android:focusable="false"     android:adjustviewbounds="true"     />  <imagebutton     android:layout_width="50dp"     android:layout_height="100dp"     android:id="@+id/editname"     android:background="@drawable/profile_settings_image"     android:layout_aligntop="@+id/nameview"     android:layout_torightof="@+id/nameview"     android:layout_toendof="@+id/nameview"     android:layout_alignbottom="@+id/nameview" />      <imagebutton     android:layout_width="50dp"     android:layout_height="50dp"     android:id="@+id/editimage"     android:background="@drawable/profile_settings_image_2"     android:layout_alignbottom="@+id/mainimage"     android:layout_alignright="@+id/mainimage"     android:layout_alignend="@+id/mainimage"     android:focusable="true" />  </relativelayout> 

if image's scale factor doesn't match imageview's scale factor, cannot match height/width without sacrificing clarity. you'll have compromise , decide if want have of image cut off, or have entire image fit inside acknowledge there left on space.

see here more information regarding android:scaletype http://www.techrepublic.com/article/clear-up-ambiguity-about-android-image-view-scale-types-with-this-guide/


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -