RelativeLayout与alignBaseline的行为不

RelativeLayout与alignBaseline的行为不

本文介绍了棉花糖RelativeLayout与alignBaseline的行为不一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android 6.0上,棉花糖无法在具有基线和layout_alignBaseline属性的RelativeLayout中相对于ImageView定位EditText.甚至可以在Android Studio的布局编辑器中观察到该行为.在实际的Android Marshmallow设备或仿真器上,在我的情况下,EditText在屏幕外移动并且不可见.我会错过一些更改吗,这是一个错误吗?

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" />

我创建了Android Studio布局编辑器的屏幕截图.这两个屏幕截图之间的区别只是API级别的更改.

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.

我创建了一个示例项目 https://github.com/mikegr/baseline

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

推荐答案

此错误报告在 https://code.google.com/p/android/issues/detail?id=73697&thanks=73697

自API11起,您可以简单地使用android:baselineAlignBottom="true"

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

在API11以下,您可以覆盖getBaseLine().

Below API11 you can overwrite getBaseLine().

更新到 Android支持库23.2.1 ,可能会解决您的问题.

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

这篇关于棉花糖RelativeLayout与alignBaseline的行为不一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:43