[英]Android - Button covering TextView in RelativeLayout only in version 5.0+
我需要实现的目标: 2行文本和1行之间的直线应始终位于Button
顶部。 因此,在这种情况下,根据我的知识,在Button
的属性中设置文本不适用。 因此,我在Button
顶部使用TextView
和View
对齐来实现它。
问题:一个奇怪的UI外观我所遇到的Android 5.0以上版本的是,当Button
被激活,它涵盖TextView
和View
,甚至之前谈到TextView
在RelativeLayout
XML文件。 (据我所知,这意味着TextView
应该位于Button
顶部)以下是我的xml代码:
<RelativeLayout
android:id="@+id/rl_daily_check_in_button_container"
android:layout_width="140dp"
android:layout_height="140dp"
android:layout_marginBottom="4dp"
android:layout_centerHorizontal="true"
android:layout_above="@+id/textview_check_in_days_in_row">
<Button
android:id="@+id/button_daily_check_in"
android:layout_width="140dp"
android:layout_height="140dp"
android:background="@drawable/daily_checkin_button" />
<TextView
android:id="@+id/textview_check_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@+id/view_line"
android:layout_marginBottom="4dp"
android:text="@string/title_not_yet_daily_check_in"
android:textColor="@color/text_gray"
android:textStyle="bold"
android:textSize="36sp" />
<View
android:id="@+id/view_line"
android:layout_width="94dp"
android:layout_height="1dp"
android:layout_centerHorizontal="true"
android:layout_above="@+id/textview_check_in_points"
android:layout_marginBottom="6dp"
android:background="@color/text_gray" />
<TextView
android:id="@+id/textview_check_in_points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="@string/points_can_get_daily_check_in_placeholder"
android:textColor="@color/text_gray"
android:textSize="14sp" />
</RelativeLayout>
但是,当应用程序在Android 5.0中(例如4.4.2)时,UI正是我所期望的。 我试图设置android:elevation="xxdp"
属性,直到我以编程方式设置Button
的背景,该属性才成功。 谁能解释原因以及Andoird 5.0+如何呈现其UI? 非常感谢!
Andoird 5.0+上的Button
:
Android 5.0-上的Button
:
在Android Lollipop(5.0)中, Button
具有默认的StateListAnimator 。 它将默认的android:elevation
和android:translationZ
属性设置为Button
。 由于已为Button
设置了默认高程,因此它会显示在未设置高程的其他视图上方(确切地说,其高程小于按钮的视图)。 即,设置了较高标高的视图将显示在具有较低标高设置的视图上方。
这就是为什么在将Button
更改为ImageView
可以解决的问题,因为ImageView
没有设置默认的elevation
。
这就是对我有用的
android:windowSoftInputMode="adjustPan"
将其添加到您正在处理的活动的活动标签中的manifest.xml中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.