(上方)按钮上的Textview,在Android 5(API 21)中不起作用 [英] Textview on(above) Button, doesn't work in Android 5(API 21)
问题描述
它看起来像是5个Android(API 21)中的错误.我需要按钮上的textview,textview应该放在按钮上方.它在Android 4.1(API 16)上正确运行,在5个Android(API 21)上错误运行.有屏幕截图和代码:
It looks like a bug in 5 Android(API 21). I need a textview on button, textview should placed above the button. It works correct on Android 4.1(API 16) and incorrect on 5 Android(API 21). There are Screenshots and code:
Android 4.1-按钮上方正确的红色textview
Android 4.1 - It is correct, red textview above the button
Android 5-它是不正确,按钮下方的红色文本视图!
Android 5 - it is incorrect, red textview under the button!
代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlBottom"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#00FF00">
<Button
android:id="@+id/bVio"
android:layout_width="wrap_content"
android:layout_height="50dip"
android:text="VIO"></Button>
<TextView
android:id="@+id/bVio_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:textSize="12dip"
android:textColor="#FFFFFF"
android:background="@drawable/rounded_textbox"/>
</FrameLayout>
</RelativeLayout>
rounded_textbox-只是形状而已...如果删除背景,所有内容看起来都一样,在5个android中按钮下的textview.
rounded_textbox - it is just shape... if remove background, all looks same, textview under button in 5 android.
请咨询!
推荐答案
是.这是Android L(API 21)的一大特色.有一个新东西-海拔高度,就像HTML中的z-index一样.因此,要修复此错误,您需要使用android:elevation ="100dp"或android:translationZ ="100dip"来查看应该位于顶部的视图.所以正确的代码是:
Yes. It is big chnage in Android L(API 21). There is new thing - Elevation, it is something like z-index in HTML. So to fix this bug you need use android:elevation="100dp" OR android:translationZ="100dip" for view that should be on top. So correct code is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlBottom"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#00FF00">
<Button
android:id="@+id/bVio"
android:layout_width="wrap_content"
android:layout_height="50dip"
android:text="VIO"></Button>
<TextView
android:id="@+id/bVio_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:textSize="12dip"
android:textColor="#FFFFFF"
android:background="@drawable/rounded_textbox"
android:elevation="100dp"/>
</FrameLayout>
</RelativeLayout>
这篇关于(上方)按钮上的Textview,在Android 5(API 21)中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!