Search code examples
androidandroid-layoutandroid-linearlayout

How to achieve that background image doesn't get stretched on linear layout


I have a linear layout with a background image. I need to scroll view before I create the linear layout. After I do that, my image on linear layout is getting stretched. Can you help me to create my image so it doesn't get stretched?

This is my code on .xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">

<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= "wrap_content"
    android:gravity="center_horizontal"
    android:background="@drawable/bg_image_login"
    android:orientation="vertical"
    android:windowSoftInputMode="stateVisible|adjustResize"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.fania.suara_project.LoginActivity">

    <ImageView
        android:id="@+id/haha"
        android:background="drawable/bg_image_login"
        android:scaleType="fitXY"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


</LinearLayout>

Help me please. Thank You :)


Solution

  • put scrollview background

    android:background="@drawable/bg_image_login"
    

    instead of Linearlayout.