为什么我的相对布局不能填满屏幕? - Android

3

我正在苦苦思考为什么我的相对布局屏幕没有填满整个屏幕。我尝试了许多方法,但是屏幕的水平空间似乎从未填满。我做错了什么?

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/splashscreen"
    android:background="@color/splashScreenBackgroundColor"
    >

    <ImageView
        android:id="@+id/imgLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:textSize="12sp"
        android:textColor="#454545"
        android:gravity="center_horizontal"
        android:layout_alignParentBottom="true"
        android:text="MyAppName"
        />

</RelativeLayout>

你能发一张截图展示你所得到的内容吗? - codeMagic
@Code-Apprentice,fill_parent与match_parent是相同的。虽然在v8中更名了,但两个名称的作用方式相同(它们具有相同的值)。 - Gabe Sechan
我看到它在垂直方向上完全填充了屏幕。而在水平方向上几乎填满了屏幕。在水平方向上,屏幕两侧大约有8%的空白空间。 - user198923
正在努力获取快照。 - user198923
你要将这个RelativeLayout添加到哪个视图中?它可能有左右填充。 - BVB
我没有将它添加到视图中,但它会出现在我的主要活动之前。目前,我的主要活动屏幕文件中没有填充和边距值。该屏幕类似于应用程序主屏幕之前的介绍屏幕,持续3秒钟后才显示应用程序的主屏幕。 - user198923
2个回答

1
旧名称已弃用,请将值更改为此。
android:layout_width="match_parent"
android:layout_height="match_parent"

添加 singletop 将替换您的活动的最后一个实例,因此如果这解决了您的问题,可能是因为您在某个地方实例化了多次活动,这就是之前不起作用的原因。

fill_parent和match_parent是相同的东西。它们因一些未知原因被重命名,但它们的作用是等效的。 - Gabe Sechan
但是fill_parent应该被替换成match_parent以避免不推荐使用的问题。无论如何,当你像这样发布答案时,应该指明在哪里更改这些值。 - codeMagic
永久更改为match_parent。再次强调,这并没有解决问题,但使用不会很快被弃用的术语是好的。 - user198923

0
我找到了一个解决方案。我在RelativeLayout中添加了“android:launchMode="singleTop"”,问题得到了解决!

1
所以问题实际上不在你发布的那部分,而是它与你没有提到的其他内容之间的关系? - david.pfx
1
这意味着当为该活动创建新的意图时,您的活动的最后一个实例将被覆盖,也许您初始化了该活动超过一次。 - Ringo
谢谢!我继续检查我的应用程序,注意到我在类调用中调用了第二个版本的应用程序,所以我将其更改为getContext(),然后删除了先前的条目,这解决了问题。谢谢 - user198923

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接