简体   繁体   English

RelativeLayout-将视图定位在ViewGroup下

[英]RelativeLayout - positioning a View under a ViewGroup

I have the following structure defined in an xml layout file. 我在xml布局文件中定义了以下结构。

<RelativeLayout android:id="@+id/mainLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<FrameLayout android:id="@+id/frame" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" ></FrameLayout>
<Button android:id="@+id/button" android:layout_below="@id/frame" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</RelativeLayout>

The FrameLayout is positioned correctly in the center of its parent. FrameLayout正确放置在其父级的中心。 But the Button isn't getting positioned under it. 但是Button并没有定位在按钮下方。 Instead it's displaying in the top left corner. 相反,它显示在左上角。

Am I doing something incorrectly or is this a bug with RelativeLayout? 我是在做错什么,还是RelativeLayout的错误?

How have you checked whether frame layout is in the center of parent or not ? 您如何检查框架布局是否位于父项的中心?

Try adding some view inside frame layout or give some fix height and width to it. 尝试在框架布局内添加一些视图,或为其提供一些固定的高度和宽度。 It might solve the problem. 它可能会解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RelativeLayout:将视图与兄弟视图组的子视图对齐 - RelativeLayout: align view to child of sibling viewgroup Android UI:自定义GIF视图在RelativeLayout中的位置 - Android UI: Positioning of custom GIF View within RelativeLayout 在两个视图(或最低视图)下定位视图 - Positioning a view under two views (or the lowest view) Android类强制转换异常:android.view.ViewGroup $ LayoutParams无法强制转换为android.widget.RelativeLayout $ LayoutParams - Android Class Cast Exception: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams java.lang.ClassCastException:android.view.ViewGroup$LayoutParams 不能转换为 android.widget.RelativeLayout$LayoutParams - java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams 将View Pager定位在Tablayout下方Coordinatorlayout - Positioning View Pager below Tablayout under Coordinatorlayout 在约束布局中的回收器视图下定位按钮 - Positioning a Button Under a Recycler View In Constraint Layout Android-在RelativeLayout中放置TextView - Android - Positioning TextView in RelativeLayout Android在RelativeLayout中的定位视图 - Android positioning views in RelativeLayout RelativeLayout对齐/定位不起作用 - RelativeLayout alignment/positioning not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM