1

I have 3 fragments aligned horizontally. I am using Relative layout for the last fragment. When I provide an ImageView in the last fragment/layout (RelativeLayout) it actually squeeze/shrinks the imageview . But when I use LineraLayout it does not. How can I get the same effect in RelativeLayout. ie with out squeezing/shrinking the components. Any help is appreciated

<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"
 android:background="#58595B">

 <ImageView
     android:id="@+id/imgProfilePhoto"
     android:layout_width="250dp"
     android:layout_height="250dp"
     android:layout_centerInParent="true"
     android:background="@drawable/contact_avatar_default_1" />

</RelativeLayout>

enter image description here

Main Layout

<LinearLayout 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"
 android:orientation="horizontal"
 android:animateLayoutChanges="true">

 <FrameLayout
     android:id="@+id/container1"
     android:layout_width="400dp"
     android:layout_height="match_parent"
     tools:context="com.sample.MainActivity"
     tools:ignore="MergeRootFrame" />

 <FrameLayout
     android:id="@+id/container2"
     android:layout_width="0dp"
     android:layout_height="match_parent"
     android:background="#E6E6E6"
     android:layout_weight="90"

     tools:ignore="MergeRootFrame" />

 <fragment
     android:id="@+id/fragmentContact"
     android:name="com.sample.photoFragment"
     android:layout_width="0dp"
     tools:layout="@layout/fragment_photo"
     android:layout_height="match_parent"
     android:layout_weight="10" />

user3121011
  • 449
  • 3
  • 12
  • in the first case, is the image cropped and viewed centred with the same original size, and if yes try to add an attribute to the imageView `ScaleType="CentreInside"` – Omar HossamEldin Apr 10 '14 at 14:58
  • No, adding scaleType="centerInside" does not make any difference. Its not only a issue to ImageView alone, it happens to VideoView, EditText etc. ie any component added to the Relative Layout cause this issue. – user3121011 Apr 10 '14 at 19:03
  • When does the resize event occur, and by what is it triggered ? – Yves Delerm Apr 11 '14 at 09:37
  • 1
    Post the entire xml code. – JJ86 Apr 11 '14 at 15:06
  • Edited the code with Main Layout – user3121011 Apr 14 '14 at 16:00
  • There is no event for Resize as of now. Please have a look on the Main Layout Code. Container 1 and Container 2 are plain layout file with sizes and weight as seen in the code. – user3121011 Apr 14 '14 at 16:02
  • based on the comments it looks like you need to force the child view's width and height even when its larger than the parent view, this is not the default functionality for android layouts http://developer.android.com/reference/android/view/View.html#attr_android:minWidth. the easiest way of doing it is probably to create a custom view that inherits from RelativeLayout or ViewGroup. http://developer.android.com/reference/android/view/ViewGroup.html – Josh Apr 16 '14 at 17:36

1 Answers1

0

Use android:layout_width="match_parent" in ImageView. Hope this work.

Kanwaljit Singh
  • 4,339
  • 2
  • 18
  • 21