如何在android Studio的顶部放置一个imageview?

问题描述 投票:0回答:2

因为它在Android工作室中显示它看起来非常好,但每当我在我的手机上运行应用程序它看起来像任何想法,请? the app on the phone and the android studio

android-layout android-studio imageview android-imageview
2个回答
0
投票

您正在使用相对布局。我在你的代码中注意到的第一件事是你在Image视图中使用了margin buttom,它已经是屏幕的顶部了。所以我建议不要使用Margin Buttom因为相对布局bydefault将图像保持在最顶层。所以我给你一些想法要解决这个问题。

1.)图像位于顶部,因此它的相对布局。 <ImageView android:id="@id/image" (give any id here) android:src="" android:marginleft="" ("Add ur dimensions") android:marginright="" android:adjustviewbound="True"/> 2.)接下来是Textview。

<TextView
        android:id="@id/text"
        android:text="Name:Lovely Hamester"
        android:layout_below="@+id/image"
        android:margintop=""/>

所以我想说的主要是这个“Id”。相对布局直接不能像线性布局一样逐行放置视图,我们需要给视图命令它需要放置的位置。这就是为什么我们使用“layout_below”它指示文本视图在imageview之后保留。还有不同的命令。请检查,如“layout_rightof”,“layout_leftof”。只需给每个视图id,并在相对布局中命令它们。你的其他代码是完美的。不要使用Margin Bottom,因为它保留了底部的空间,在预览中看起来很完美,但每个Mobile都有不同的大小,这就是为什么它不显示完美的你的屏幕。


-1
投票

问题,因为我看到你有一个边距底部覆盖布局对齐父顶部所以如果你删除它并只留下:

android:layout_alignParentTop="true"

调用左右对齐也是多余的,对齐顶部就足够了。

我相信它会奏效。

© www.soinside.com 2019 - 2024. All rights reserved.