1

I got the problem with ImageView position after I load picture. On the beginning when I lunch the application I have sample picture in ImageView, then after choosing another one from gallery, the old one is replacing by new and unluckily the imageView changes position in the same moment. How to block it ? How to make ImageView be at this same position for all the time?

This is my xaml code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<EditText
    android:id="@+id/add_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="66dp"
    android:ems="10"
    android:hint="add name of product"
    android:inputType="textPersonName" />

<TextView
    android:id="@+id/prod_show_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="Name of Product"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
    android:id="@+id/add_description"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/prod_show_description"
    android:layout_marginTop="31dp"
    android:ems="10"
    android:hint="here put the description of product "
    android:inputType="textMultiLine" />

<TextView
    android:id="@+id/prod_show_description"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/add_name"
    android:layout_marginTop="31dp"
    android:text="Description Of Product "
    android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
    android:id="@+id/add_picture"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/prod_show_description"
    android:layout_below="@+id/add_description"
    android:layout_marginRight="22dp"
    android:layout_marginTop="45dp"
    android:maxHeight="120dp"
    android:maxWidth="120dp"
    android:minHeight="120dp"
    android:minWidth="120dp"
    android:scaleType="centerInside"
    android:src="@drawable/sample" >
</ImageView>

<Button
    android:id="@+id/add_addpicture"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/add_picture"
    android:layout_marginRight="141dp"
    android:minHeight="80dp"
    android:onClick="AddPicture"
    android:text="Add Picture " />

<Button
    android:id="@+id/add_addingbut"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/add_picture"
    android:layout_marginTop="119dp"
    android:onClick="AddTheProductMethod"
    android:text="Add the product" />

MyWay
  • 1,011
  • 2
  • 14
  • 35
  • Hi,This is because they're both in a `RelativeLayout`, which leads me to believe, that the two images are of different sizes. Pelase tell me the size of the image `sample` and the one you're putting later in the `ImageView`? – g00dy Nov 06 '13 at 14:50
  • you have `layout_width` `wrap_content` and also `minWidth` 120dp and `maxWidth` 120dp. same for height. this is very unusual to do. just leave out `minWidth` and `maxWidth` and make your `layout_width` 120 dp – Ivo Nov 06 '13 at 14:58
  • the sample picture is in drawable xhdpi and the file which was copied to this folder is 336x299, the picture which is putted later is made by camera of the tablet(2560x1920), but it has any significant, if my imageView scaling it ("android:scaleType="centerInside"") and have constant size? – MyWay Nov 06 '13 at 14:59

1 Answers1

3

change imageview android:layout_height and android:layout_width to 120dip its better to use dip not dp

<ImageView
    android:id="@+id/add_picture"
    android:layout_width="120dip"
    android:layout_height="120dip"
    android:layout_alignRight="@+id/prod_show_description"
    android:layout_below="@+id/add_description"
    android:layout_marginRight="22dp"
    android:layout_marginTop="45dp"
    android:scaleType="centerInside"
    android:src="@drawable/sample" >
</ImageView>
Noob
  • 2,857
  • 6
  • 33
  • 47
  • `dip` and `dp` is the same. It is perfectly fine to use `dp`. but I agree to leave out the `minHeight` `maxHeight` stuff and put that value in `layout_height`. see also http://stackoverflow.com/questions/7608251/is-dp-the-same-as-dip – Ivo Nov 06 '13 at 15:01
  • sure , i made research for long time ago about `dp` and `dip` for android all google developers recommended to use `dip` not `dp` for imageView its just an advice :) – Noob Nov 06 '13 at 15:04
  • Yeah its working, thx but I my question is why ? wrap_content means that it takes only area to show the picture inside. So when I wouldn't place any limits It would be as big as picture, but I put limits maxheight and maxwidth. The imageView didn't change the size only position, so I could say that my limits works – MyWay Nov 06 '13 at 15:13