How to remove margin top from Imageview

Asked

Viewed 50 times

0

Hi, I’m creating an app, and I have an Imageview with the id ivthumb that’s at the top but for some reason it doesn’t stick to the top and gets a little space. Can anyone help me solve this problem? PS: I remove the Action Bar with getSupportActionBar(). Hide(); if you have anything to do with it.

Imagery:

https://ibb.co/QJLFFFsD

XML:

<?xml version="1.0" encoding="utf-8"?>
    <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:background="#15202b"
        android:padding="0dip"
        tools:context=".ViewMateria">

        <ImageView
            android:id="@+id/ivthumb"
            android:layout_width="match_parent"
            android:layout_height="232dp"
            />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="237dp"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/back"
                android:layout_width="37dp"
                android:layout_height="44dp"
                android:layout_marginTop="9sp"
                android:onClick="voltar"
                app:srcCompat="@drawable/ic_back" />

        </LinearLayout>

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="501dp"
                    android:layout_marginTop="230sp"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/tvvtitle"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="5sp"
                        android:text=""
                        android:textAlignment="center"
                        android:textColor="#fff"
                        android:textSize="23sp" />

                    <TextView
                        android:id="@+id/tvdesc"
                        android:layout_width="399dp"
                        android:layout_height="match_parent"
                        android:layout_marginLeft="5sp"
                        android:layout_marginTop="5sp"
                        android:text=""
                        android:textSize="15sp"
                        android:textColor="#fff" />
                </LinearLayout>
            </LinearLayout>
        </ScrollView>

    </RelativeLayout>

1 answer

1


Check alignment of your ImageView. Using the property layout_alignParentTop= true you will ensure that the top of the component will be connected to the top of your parent layout. If the margin continues to appear, change the scaleType for centerCrop, in order to fill the entire surface of Imageview with the content of the image, maintaining the ratio.

If this still doesn’t resolve, use the Layoutinspector to investigate the size and positioning properties of your Imageview in Runtime.

When developing interfaces, be careful when defining fixed sizes for components, as this can make the screen composition difficult, especially when there is a very large variation in the size of the devices running the application. Give preference to the use of match_parent and wrap_content, or, use the ConstraintLayout to define more dynamic sizes and proportions.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.