0

I have a bunch of gifs of different sizes and I want to align then in a horizontal ListView so that they're all the same height, obviously not necessarily the same width.

We are using https://github.com/koral--/android-gif-drawable

Example: enter image description here

Gif display xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:paddingLeft="10dp"
    android:id="@+id/holder"
    android:paddingTop="5dp"
    android:paddingBottom="5dp">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <pl.droidsonroids.gif.GifTextureView
            android:layout_width="100dp"
            android:id="@+id/gif_rec_view"
            android:layout_height="100dp"
            android:layout_centerHorizontal="true"
            />
    </RelativeLayout>

</RelativeLayout>

Container

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_below="@+id/title1"
    android:layout_marginTop="5dp"
    android:background="@android:color/transparent"
    android:id="@+id/xD">
    <com.devsmart.android.ui.HorizontalListView
        android:id="@+id/gif_search_1"
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:background="#e3e3e3"
        />
</RelativeLayout>

Load gif into view:

final GifTextureView textureView = (GifTextureView) convertView.findViewById(R.id.gif_rec_view);
LoadGif gLoad = new LoadGif(_objects.get(position).url, textureView);
gLoad.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[])null);

How would I best solve this? Tried bunch of stuff.

//textureView.setLayoutParams(new RelativeLayout.LayoutParams(_objects.get(position).width, _objects.get(position).height));
//RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
//params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
//textureView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

Edit 1:

So looking at this thread: How to scale an Image in ImageView to keep the aspect ratio

using

android:adjustViewBounds="true"
android:scaleType="centerCrop"

worked wonders, however the images cropped like so:

enter image description here

and

android:adjustViewBounds="true"
android:layout_centerInParent="true"

did not work at all.

Ezzy
  • 1,423
  • 2
  • 15
  • 32

1 Answers1

0

Okay so this is how I managed to solve it:

Gif display xml

<pl.droidsonroids.gif.GifTextureView
    android:layout_width="150dp"
    android:layout_height="match_parent"
    android:id="@+id/gif_rec_view"
    android:layout_centerHorizontal="true"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    />

Adapter

/*Absolutely fucking ridiculous*/
textureView.setLayoutParams(new RelativeLayout.LayoutParams(Utils.pxToDp(_objects.get(position).width), Utils.pxToDp(_objects.get(position).height)));

Utils ...

public static int pxToDp(int px)
{
    //return (int) (px / Resources.getSystem().getDisplayMetrics().density);
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, px, Resources.getSystem().getDisplayMetrics());
}

enter image description here

Hope this may help some lone wanderer in the future.

Ezzy
  • 1,423
  • 2
  • 15
  • 32