如何将图像视图放在Android Studio的顶部



正如Android Studio中所示的那样,它看起来很好,但是每当我在手机上运行该应用程序时,都会有任何想法吗?电话上的应用程序和Android Studio

您正在使用相对布局。我在您的代码中注意到的第一件事是,您在屏幕顶部使用了图像视图中的保证金对接。因此,我建议不要在此中使用保证金对接,因为相对布局bydefault 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并在相对布局中命令它们。您的屏幕。

只需将代码图像视图移动到顶部

示例

<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>

我看到的问题是,您的保证金底部覆盖了布局对准父上衣,因此,如果您删除并仅离开:

android:layout_alignParentTop="true"

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

我确定它会起作用。

相关内容