10

On Android 6.0 Marshmallow the positioning of an EditText in relation to an ImageView in a RelativeLayout with the attributes baseline and layout_alignBaseline does not work anymore. The behaviour can even be observed in the layout editor in Android studio. On a real Android Marshmallow device or emulatr the EditText in my case is shift outside the screen and not visible. Do I miss some changes, is it a bug?

<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivityFragment">

<ImageView
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:id="@+id/imageView"
    android:src="@drawable/icon_category_geography_raster"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:baselineAlignBottom="true"
    android:background="#00ffff"
     />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/editText"
    android:layout_alignParentTop="true"
    android:layout_toRightOf="@id/imageView"
    android:background="#ff0000"
    android:inputType="text"
    android:hint="Hint"
    android:layout_alignBaseline="@id/imageView" />

I have created screenshots of the Layout Editor of Android Studio. The difference between these two screenshots is solely the change of the API level.

I have created a sample project https://github.com/mikegr/baseline

Layout Editor with API Level 22 Layout Editor with API Level 23

Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
Michael Greifeneder
  • 2,900
  • 3
  • 18
  • 19
  • This certainly feels like a bug. I can reproduce your findings from your sample app. Your `EditText` (or `AppCompatEditText` as it turns into) winds up having a negative vertical position according to Hierarchy View (mBottom = -193, mTop = -230 on a WVGA800-sized emulator screen). – CommonsWare Oct 07 '15 at 21:20
  • Has anyone reported this to Google? – Zharf Oct 21 '15 at 11:06
  • Carlton Whitehead has reported the bug here: https://code.google.com/p/android/issues/detail?id=190839 – Michael Greifeneder Oct 21 '15 at 14:30

1 Answers1

0

This is bug reported on https://code.google.com/p/android/issues/detail?id=73697&thanks=73697

Since API11 you can simply use android:baselineAlignBottom="true"

Below API11 you can overwrite getBaseLine().

Update to Android Support Library 23.2.1, this may solve your problem.

Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142