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

时间:2017-12-25 11:12:05

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

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

3 个答案:

答案 0 :(得分: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 :(得分:0)

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

示例

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

答案 2 :(得分:-1)

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

android:layout_alignParentTop="true"

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

我确定它会起作用。