Android layout 如何在android Studio中将imageview放置在顶部?
正如android studio中显示的那样,它看起来非常好,但每当我在手机上运行应用程序时,它看起来就像这样。有什么想法吗 您正在使用相对布局。 我在代码中注意到的第一件事是,您在屏幕顶部的图像视图中使用了边距按钮。因此,我建议不要在该视图中使用边距按钮,因为相对布局默认情况下会将该图像保持在顶部。因此,我给您一些修复它的方法 1.)图像位于顶部so及其相关布局。Android layout 如何在android Studio中将imageview放置在顶部?,android-layout,android-studio,imageview,android-imageview,Android Layout,Android Studio,Imageview,Android Imageview,正如android studio中显示的那样,它看起来非常好,但每当我在手机上运行应用程序时,它看起来就像这样。有什么想法吗 您正在使用相对布局。 我在代码中注意到的第一件事是,您在屏幕顶部的图像视图中使用了边距按钮。因此,我建议不要在该视图中使用边距按钮,因为相对布局默认情况下会将该图像保持在顶部。因此,我给您一些修复它的方法 1.)图像位于顶部so及其相关布局。 2.)接下来是文本视图 <TextView android:id="@id/text"
2.)接下来是文本视图
<TextView
android:id="@id/text"
android:text="Name:Lovely Hamester"
android:layout_below="@+id/image"
android:margintop=""/>
所以我想指出的主要问题是这个“Id”。相对布局不能像线性布局那样直接将视图逐行放置,我们需要将命令发送到视图需要放置的位置。这就是为什么我们使用“下面的布局”来指示文本视图停留在imageview之后。也有不同的命令。请检查一下,如“Layou rightof”,“左侧布局”。
只需为每个视图指定id,并在相对布局中命令它们。您的其他代码是完美的。不要使用边距底部,因为它保留了底部的空间,这在预览中看起来很完美,但每个手机都有不同的大小,这就是为什么它在屏幕上显示不完美的原因。我看到的问题是,边距底部覆盖了布局ut对齐父顶部,因此如果删除并仅保留:
android:layout_alignParentTop="true"
另外,它是多余的调用对齐的权利和左侧和底部,对齐顶部将足够
我确信它会工作。只需将代码图像视图移到顶部即可 范例
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<ImageView
android:layout_width="200dp"
android:layout_height="600dp"
android:src="@drawable/test"/>
<ProgressBar
android:layout_width="48dp"
android:layout_height="48dp"
android:id="@+id/progressbar"
android:layout_centerInParent="true"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_notes"
android:layout_width="250dp"
android:layout_height="match_parent"
tools:listitem="@layout/item_note"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_margin="16dp"
android:src="@drawable/button"
app:borderWidth="1dp"
app:elevation="9dp"
android:backgroundTint="#FFFFFF"/>
</RelativeLayout>
您已经在shaa\u allah\u仓鼠.xml中包含了您的活动图片。请编辑您的问题并将其作为文本发布,以便我们可以帮助您粘贴您的xml代码。非常感谢您……添加此代码后,问题已得到解决:android:adjustviewbound=“True”“欢迎光临:)。有关android相关问题,请随时与我联系。我们需要在此问题旁边添加代码:android:adjustviewbound=“True”android:layout\u alignParentTop=“True”,谢谢您的帮助:D