Szukam adoptować Glide library zamiast Universal Image Loader, ale mam problem z przejściami elementów współużytkowanych.Biblioteka systemu Android Glide nie działa z przejściami elementów współużytkowanych
W moim prostym Sandbox Utworzyłem następujące przejścia przy użyciu UIL: https://dl.dropboxusercontent.com/u/97787025/device-2015-06-18-113333.mp4
Całkiem proste, i to działa dobrze. Ale kiedy użyłem Glide, że nie wygląda tak miły: https://dl.dropboxusercontent.com/u/97787025/device-2015-06-18-114508.mp4
Oto kod używam
pierwszej czynności:
public class MainActivity extends BaseActivity {
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.main);
final ImageView iv = (ImageView) findViewById(R.id.main_image);
displayImageGlide(BaseActivity.IMAGE_URL, iv, true);
Button button = (Button) findViewById(R.id.main_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), DifferentActivity.class);
startActivity(intent, iv);
}
});
}
}
a drugi:
public class DifferentActivity extends BaseActivity {
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.different);
ImageView imageView = (ImageView) findViewById(R.id.diff_image);
displayImageGlide(BaseActivity.IMAGE_URL, imageView, false);
}
}
BaseActivity zawiera po prostu displayImageGlide
public void displayImageGlide(String url, ImageView imageView) {
Glide.with(this).load(url)
.asBitmap().transform(new CustomTransformation(this))
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(imageView);
}
private static class CustomTransformation extends BitmapTransformation {
public CustomTransformation(Context context) {
super(context);
}
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
return bitmapChanger(toTransform, outWidth, outHeight);
}
@Override
public String getId() {
return "some_id_1";
}
}
private static Bitmap bitmapChanger(Bitmap bitmap, int desiredWidth, int desiredHeight) {
float originalWidth = bitmap.getWidth();
float originalHeight = bitmap.getHeight();
float scaleX = desiredWidth/originalWidth;
float scaleY = desiredHeight/originalHeight;
//Use the larger of the two scales to maintain aspect ratio
float scale = Math.max(scaleX, scaleY);
Matrix matrix = new Matrix();
matrix.setScale(scale, scale);
//If the scaleY is greater, we need to center the image
if(scaleX < scaleY) {
float tx = (scale * originalWidth - desiredWidth)/2f;
matrix.postTranslate(-tx, 0f);
}
Bitmap result = Bitmap.createBitmap(desiredWidth, desiredHeight, bitmap.getConfig() != null ? bitmap.getConfig() : Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
canvas.drawBitmap(bitmap, matrix, new Paint());
return result;
}
Próbowałem usunąć linie pamięci podręcznej z budowniczego Glide (używane, aby zapobiec buforowaniu tego, co próbuję poprawić), ale to nie pomogło. Chciałbym przyjąć Glide, ale jest to rodzaj łamacza transakcji, jeśli to nie zadziała. Jeśli ktokolwiek ma jakiś wkład, to byłbym wdzięczny, dzięki!
nie wykorzystali Glide ale myślę, transformacja przełącza obrazy w locie co powoduje zacinać podczas animacji. Czy ustawienie "android: scaleType =" centerCrop "' na ImageView nie rozwiąże problemu? –
centerCrop nie jest typem skali, który chcę, jednak metoda CustomTransformation stosuje niestandardową macierz do mapy bitowej, która tworzy obraz, który ładnie pasuje do granic. – JMRboosties