Home » Java » How to scroll ImageView horizontal in Android?

How to scroll ImageView horizontal in Android?

Posted by: admin September 21, 2018 Leave a comment

Questions:

In my application I want show image from server into ImageView.
My imageView fill the all of screen and for this I use android:scaleType="centerCrop" .

But when use centerCrop not show all of the image detail?

I want horizontal scroll on imageView automatically (with normal speed) of by user finger.

My XML code :

<ImageView
    android:id="@+id/wallpaperDetail_img"
    android:layout_width="match_parent"
    android:layout_height="patch_parent"
    android:scaleType="centerCrop" />

My Full XML code:

    <?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"
    tools:context=".activity.Wallpapers.WallpaperDetailActivity">

    <include
        android:id="@+id/wallpaperDetail_toolbar"
        layout="@layout/toolbar_simple" />

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_below="@id/wallpaperDetail_toolbar"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/wallpaperDetail_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="centerCrop" />
    </HorizontalScrollView>

    <ProgressBar
        android:id="@+id/wallpaperDetail_loader"
        android:layout_width="@dimen/size25"
        android:layout_height="@dimen/size25"
        android:layout_centerInParent="true"
        android:visibility="gone" />

    <io.github.yavski.fabspeeddial.FabSpeedDial
        android:id="@+id/wallpaperDetail_fabMenu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:visibility="gone"
        app:fabGravity="bottom_end"
        app:fabMenu="@menu/menu_wallpaper_detail"
        app:miniFabBackgroundTintList="@array/fab_menu_item_colors"
        app:fabBackgroundTint="@color/catMenuColor2"
        app:miniFabDrawableTint="@android:color/white"
        app:miniFabTitleTextColorList="@array/fab_menu_item_colors"
        app:touchGuardDrawable="@drawable/background" />

</RelativeLayout>

My java code for get image from server :

    Glide.with(context)
            .load(imageUrl)
            .asBitmap()
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .into(wallpaperDetail_img);

How can I horizontal scroll on ImageView? How can I it?

Answers: