I can’t adjust the image size to the layout

Asked

Viewed 199 times

0

Hello I would like to change the layoutgravity of the image, which will always be filled on the sides and at the top. I change the layoutgravity but does not change anything. Example below:

inserir a descrição da imagem aqui

Screen Code:

<LinearLayout 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:orientation="vertical"
    tools:context="com.example.aluno.tiposdeenergia.solar"
    android:background="@mipmap/background_foto1">

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

            <ImageView
                android:layout_height="230dp"
                android:layout_width="match_parent"
                app:srcCompat="@mipmap/energiasolar_foto2" />

            <TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="25dp"
                android:layout_marginTop="5dp"
                android:fontFamily="monospace"
                android:text="Fontes de Energia Sustentáveis no Brasil"
                android:textSize="24sp"
                android:textStyle="bold|italic" />

            <TextView
                android:id="@+id/EnergiaSolar_Text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_weight="1"
                android:fontFamily="serif-monospace"
                android:text="@string/Solar"
                android:textAlignment="textStart"
                android:textSize="24sp"
                android:textStyle="bold" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>
  • you want it to get filled up on the sides or how is it? explains your problem and what you want because you probably won’t even need to touch the Gravity layout

  • is filled up and on the sides and always in the top position

  • i try to use the matchparent at the height of the image but it does not fill, only fill all when I put 230dp

  • So bro, the image she has the size of her, and when you put in the imageview with the different dimensions of the image she doesn’t fill even no, do the following go in layout-Weight and arrow 1 and tell me if it worked

  • Nothing has changed, even with the height in matchparent or 230dp

Show 1 more comment

1 answer

2


Now I understand the problem. You have two options, this:

<ImageView
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:layout_weight="1"
   android:adjustViewBounds="true"
   app:srcCompat="@mipmap/energiasolar_foto2" />

Or that:

<ImageView
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:layout_weight="1"
   android:scaleType="fitXY"
   app:srcCompat="@mipmap/energiasolar_foto2" />

Uses in the image android:adjustViewBounds="true" or android:scaleType="fitXY". Adjust the other elements to not overlap.

Browser other questions tagged

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