【问题标题】:How to place an imageview on the top in android Studio?如何在android Studio的顶部放置一个imageview?
【发布时间】:2017-12-25 11:12:04
【问题描述】:

正如它在 android studio 中显示的那样,它看起来非常好,但是每当我在我的手机上运行该应用程序时,它看起来像这样任何想法,拜托?? the app on the phone and the android studio

【问题讨论】:

  • 您已经包含了您的 activity_inshaa_allah_hamster.xml 的图片。请编辑您的问题并将其作为文本发布,以便我们为您提供帮助
  • 你能粘贴你的xml代码吗

标签: android-layout android-studio imageview android-imageview


【解决方案1】:

您正在使用相对布局。 我在您的代码中注意到的第一件事是您已经在屏幕顶部的图像视图中使用了边距按钮。所以我建议不要在其中使用边距按钮,因为默认情况下相对布局会将该图像保持在顶部。所以我给你一些想法修复它。

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”指示文本视图停留在图像视图之后。还有不同的命令。请检查,如“layout_rightof”、“layout_leftof”。 只需为每个视图提供 id 并在相对布局中命令它们。您的其他代码是完美的。不要使用 Margin Bottom ,因为它保留了底部的空间,在预览中看起来很完美,但每个移动设备都有不同的大小,所以这就是为什么它不能显示完美你的屏幕。

【讨论】:

  • 非常感谢...添加此代码后问题已解决:android:adjustviewbound="True"
  • 欢迎您 :)。如有 Android 相关问题,请随时联系我
【解决方案2】:

只需将代码 imageview 移到顶部

例子

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

【讨论】:

    【解决方案3】:

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

    android:layout_alignParentTop="true"
    

    调用 align right and left 和 bottom 也是多余的, align top 就足够了。

    我相信它会起作用的。

    【讨论】:

    • 我们需要在这个 android:layout_alignParentTop="True" 旁边添加代码:android:adjustviewbound="True",感谢帮助:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 2015-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多