Android layout_below in RelativeLayout -


i came across strange issue, below layout:

<relativelayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content" >  <imageview     android:src="@color/coloraccent"     android:layout_width="match_parent"     android:layout_height="200dp"/> <imageview     android:id="@+id/image"     android:src="@mipmap/ic_launcher"     android:layout_centerinparent="true"     android:layout_width="wrap_content"     android:layout_height="wrap_content"/>  <textview     android:text="text"     android:layout_below="@+id/image"     android:layout_width="wrap_content"     android:layout_height="wrap_content"/> </relativelayout> 

enter image description here

textview not below imageview expected, it's below original position of imageview.

if set layout_height of relativelayout 200dp or match_parent, works fine.

how solve this?

simple solution use android:layout_height="match_parent" in root layout.

if using wrap_content root layout, android:layout_centerinparent , android:layout_below not work properly.

either use height match_parent or static.

choice 1 :

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="200dp"> 

choice 2 :

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

choice 3:

<linearlayout     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_centerinparent="true"     android:orientation="vertical">      <imageview         android:id="@+id/image"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/ic_launcher" />      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="text" /> </linearlayout> 

now upto use solution.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -