2016-11-26 2 views
0

Ich habe eine Reihe von Gifs in verschiedenen Größen und ich möchte dann in einer horizontalen ListView ausrichten, so dass sie alle die gleiche Höhe haben, offensichtlich nicht unbedingt die gleiche Breite.Scale Gifs für eine horizontale ListView

Wir verwenden https://github.com/koral--/android-gif-drawable

Beispiel: enter image description here

Gif Anzeige 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> 

Last gif in Ansicht:

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); 

Wie würde ich das am besten lösen? Ausprobiert Haufen Zeug.

//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:

Also auf diesen Thread suchen: How to scale an Image in ImageView to keep the aspect ratio

mit

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

Wunder gewirkt, aber die Bilder wie so abgeschnitten:

enter image description here

und

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

nicht bei allen.

Antwort

0

Okay, so ist dies, wie ich es lösen verwaltet:

Gif Anzeige 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

Hoffe, dass dies einige einsame Wanderer in der Zukunft helfen kann.