android-RelativeLayout中的layout_centerInParent不在模拟器或设备上居中

android-RelativeLayout中的layout_centerInParent不在模拟器或设备上居中,第1张

概述我有一个这样的布局片段:<RelativeLayout xmlns:android='http://schemas.android.com/apk/res/android' android:layout_width='match_parent' android:layout_height='match_parent'>

我有一个这样的布局片段:

<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent">    <TextVIEw        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:text="My Fragment"        androID:textSize="30sp"        androID:layout_centerInParent="true"/></relativeLayout>

在AndroID Studio预览中,我看到了以下内容:

很好,但是在模拟器或真实设备上,我看到了:

我想念什么?如何在父母中居中显示该文本?

父布局是FrameLayout:

<linearLayout    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:orIEntation="vertical">    <androID.support.v7.Widget.Toolbar        androID:layout_wIDth="match_parent"        androID:layout_height="?attr/actionbarSize"        androID:ID="@+ID/toolbar"/>    <FrameLayout        androID:layout_wIDth="wrap_content"        androID:layout_height="match_parent"        androID:ID="@+ID/frame_layout">    </FrameLayout></linearLayout>
最佳答案您需要更改FrameLayout的宽度

将您的FrameLayout宽度更改为androID:layout_wIDth =“ match_parent”

样本代码

<linearLayout    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:orIEntation="vertical">    <androID.support.v7.Widget.Toolbar        androID:layout_wIDth="match_parent"        androID:layout_height="?attr/actionbarSize"        androID:ID="@+ID/toolbar"/>    <FrameLayout        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:ID="@+ID/frame_layout">    </FrameLayout></linearLayout>
总结

以上是内存溢出为你收集整理的android-RelativeLayout中的layout_centerInParent不在模拟器或设备上居中 全部内容,希望文章能够帮你解决android-RelativeLayout中的layout_centerInParent不在模拟器或设备上居中 所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1145009.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存