当应用材料主题渲染错误为了按钮 [英] Wrong render order for button when material theme is applied
问题描述
按钮控件借鉴了其他部件的顶部不管布局结构是什么。
当应用材料深/浅主题。它重复两RelativeLayout的和的FrameLayout。
检查出的截图娄更好地说明这种奇怪的行为。
Button widget draws on top of any other widget no matter what the layout structure is. It repeats in both RelativeLayout and FrameLayout when Material Dark/Light theme is applied. Check out screenshots bellow for better illustration of this strange behaviour.
经过在Nexus 4和Nexus 5,但是我怀疑它关系到设备上。
Checked on Nexus 4 and Nexus 5. However I doubt it is related to devices.
任何想法男士?
推荐答案
是Android 5.0棒棒糖随着材料设计引入了新的属性来指定控件的高度(Z-指数)。它被描述这里。
Android 5.0 Lollipop along with Material Design introduced new property to specify the elevation (Z-index) of widgets. It is described here.
要画到按钮的观点,您可以添加的android:海拔=1DP
来查看
To draw the view over the button you can add android:elevation="1dp"
to the View
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Don't look so deep"
/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C00"
android:elevation="1dp"
/>
的以下是早答案误解问题的一部分,保留以备将来参考的
使用RelativeLayout的,你必须指定相对于其他元素的元素的位置。
With RelativeLayout you have to specify the position of elements relative to other elements.
所以说,你想拥有的查看
下面的按钮,你就必须ID的添加元素,并指定该视图按钮如下:
So say you want to have the View
below the button, you'll have to add id's to the elements and specify that the view is below the button:
<Button
android:id="+id/myactivity_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Don't look so deep"
/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C00"
android:layout_below="@id/myactivity_button"
/>
查看 Android开发者指南的RelativeLayout 和可用于LayoutParameters RelativeLayouts
Check out the Android Developer Guide for RelativeLayout and the available LayoutParameters for RelativeLayouts
的FrameLayout
通常是不利于组织多个组件。所述的FrameLayout被设计为阻挡的区域中的屏幕上显示单个项目。在孩子的的FrameLayout的位置可以通过使用机器人进行控制。layout_gravity
属性
FrameLayout
is usually not good for organize multiple components. The FrameLayout is designed to block out an area on the screen to display a single item. The position of the FrameLayout childs can be controlled by using the android:layout_gravity
attribute.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:text="Don't look so deep"
/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C00"
android:layout_gravity="bottom"
/>
查看的Android文档进行的FrameLayout 和<一个href=\"http://developer.android.com/reference/android/widget/FrameLayout.LayoutParams.html#attr_android:layout_gravity\"相对=nofollow>可用于layout_gravity 参数
这篇关于当应用材料主题渲染错误为了按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!