毕加索占位符比例适合中心屏幕

问题描述 投票:0回答:2

我正在尝试使用Picasso实现占位符动画,在从Web加载时为自定义动画设置动画。我已经寻找了很多解决方案,我无法找到缩小动画并使其居中的方法。结果是有时动画被拉伸,居中或在一个角落中播放。

动画图像明显小于图像视图和下载的图像。

这是我目前使用的代码:

Picasso.with(getActivity()).load(imageUri).fit()//.placeholder(R.drawable.progress_animation)
                .placeholder(R.drawable.progress_animation)
                        .into(mIconView);

这是动画定义:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"

android:id =“@ + id / selected”android:oneshot =“false”>

<item android:drawable="@drawable/wheel1" android:duration="50" />
<item android:drawable="@drawable/wheel2" android:duration="50" />
<item android:drawable="@drawable/wheel3" android:duration="50" />
<item android:drawable="@drawable/wheel4" android:duration="50" />
<item android:drawable="@drawable/wheel5" android:duration="50" />

关于如何控制毕加索动画比例和位置的任何建议,我找不到使用fit()或resize()的方法,因为它只影响最终图像而不影响占位符,并试图使用其中两个造成碰撞。

android animation placeholder picasso
2个回答
1
投票

我找到了一种使用进度条并回拨的方法。

 mProgressView.setVisibility(View.VISIBLE);
            Picasso.with(getActivity()).load(f).fit()

                    .into(mIcon,new Callback() {
                        @Override
                        public void onSuccess() {
                            mProgressView.setVisibility(View.GONE);
                        }

                        @Override
                        public void onError() {
                            // TODO Auto-generated method stub

                        }
                    });

这是布局部分

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"

>
<ImageButton
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:id="@+id/ib_place_dialog_image"
    android:maxHeight="200dp"
    android:layout_gravity="center_horizontal"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />
<ProgressBar
    style="?android:attr/progressBarStyleLarge"
    android:scaleX="0.4"
    android:scaleY="0.4"
    android:layout_width="128dp"
    android:layout_height="128dp"
    android:id="@+id/cliff_image_progress_bar"

    android:indeterminateDrawable="@drawable/progress_animation"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

和动画

   <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/selected" android:oneshot="false">

    <item android:drawable="@drawable/frame_0" android:duration="30" />
    <item android:drawable="@drawable/frame_0" android:duration="30" />
<item android:drawable="@drawable/frame_0" android:duration="30" />
<item android:drawable="@drawable/frame_1" android:duration="30" />
<item android:drawable="@drawable/frame_2" android:duration="30" />
<item android:drawable="@drawable/frame_3" android:duration="30" />
<item android:drawable="@drawable/frame_4" android:duration="30" />
<item android:drawable="@drawable/frame_5" android:duration="30" />
<item android:drawable="@drawable/frame_6" android:duration="30" />
<item android:drawable="@drawable/frame_7" android:duration="30" />
<item android:drawable="@drawable/frame_8" android:duration="30" />
<item android:drawable="@drawable/frame_9" android:duration="30" />
<item android:drawable="@drawable/frame_10" android:duration="30" />
<item android:drawable="@drawable/frame_11" android:duration="30" />
<item android:drawable="@drawable/frame_12" android:duration="30" />
<item android:drawable="@drawable/frame_13" android:duration="30" />
<item android:drawable="@drawable/frame_14" android:duration="30" />
<item android:drawable="@drawable/frame_15" android:duration="30" />
<item android:drawable="@drawable/frame_16" android:duration="30" />
<item android:drawable="@drawable/frame_17" android:duration="30" />
<item android:drawable="@drawable/frame_18" android:duration="30" />
<item android:drawable="@drawable/frame_19" android:duration="30" />
<item android:drawable="@drawable/frame_20" android:duration="30" />
<item android:drawable="@drawable/frame_21" android:duration="30" />
<item android:drawable="@drawable/frame_22" android:duration="30" />
<item android:drawable="@drawable/frame_23" android:duration="30" />
<item android:drawable="@drawable/frame_24" android:duration="30" />
<item android:drawable="@drawable/frame_25" android:duration="30" />
<item android:drawable="@drawable/frame_26" android:duration="30" />
<item android:drawable="@drawable/frame_27" android:duration="30" />
<item android:drawable="@drawable/frame_28" android:duration="30" />
<item android:drawable="@drawable/frame_29" android:duration="30" />



</animation-list>

0
投票

我使用了loran ditsum的代码,但我更改了onSucces方法=

在xml中,Post_image ScaleType是centerinside

    Picasso.with(context)
                    .load(imagen)
                    .placeholder(R.drawable.progress_animation)
                    .into(Post_image,new Callback() {
                        @Override
                        public void onSuccess() {
                            Post_image.setScaleType(ImageView.ScaleType.FIT_XY); 
// when the image is loaded it changes the scaletype

                        }

                        @Override
                        public void onError() {
                            // TODO Auto-generated method stub

                        }
                    });   

0
投票

试试这个

 Picasso.get()
                        .load(source).resize(1650,700)
                        .centerCrop(Gravity.CENTER).into(imageView, new Callback() 
© www.soinside.com 2019 - 2024. All rights reserved.