0
我有一堆不同大小的gif,我想在水平ListView中對齊,以便它們都是相同的高度,顯然不一定是相同的寬度。縮放gif以適合水平ListView
我們使用https://github.com/koral--/android-gif-drawable
的Gif顯示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>
集裝箱
<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>
負載GIF眼簾:
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);
我如何能最好地解決這個問題? 試過一堆東西。
//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));
編輯1:
所以在看這個線程:How to scale an Image in ImageView to keep the aspect ratio
使用
android:adjustViewBounds="true"
android:scaleType="centerCrop"
創造了奇蹟,但是圖像裁剪,像這樣:
和
android:adjustViewBounds="true"
android:layout_centerInParent="true"
沒有在所有的工作。