Glitchy在半径为

时间:2018-06-01 06:05:12

标签: android animation android-animation

我一直在创建一个应用程序,其中我有一个片段,其中我有一个带有图像的cardview,我已经在tutorial的帮助下实现了共享元素转换。但是,当我将半径应用于cardview时,转换看起来非常糟糕。我看到了这个SO question,但这并没有解决问题,所以我期待在这里提供一些帮助。 谢谢。

这是片段代码

 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_feed, container, false);
        getActivity().getWindow().setExitTransition(null);
        setRetainInstance(true);
        toolbar = (Toolbar)view.findViewById(R.id.toolbar);
        // ((MainActivity)getActivity()).setSupportActionBar(toolbar);
        feed_recycler_view = (RecyclerView)view.findViewById(R.id.feed_recycler_view);
        //ViewCompat.setNestedScrollingEnabled(feed_recycler_view, false  );
        CustomTextView customTextView = (CustomTextView)toolbar.findViewById(R.id.toolbar_title);


        feed_layout_manager = new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false);
        feed_recycler_view.setLayoutManager(feed_layout_manager);
        //feed_recycler_view.setNestedScrollingEnabled(false);
        feed_recycler_view.setHasFixedSize(true);
        feed_adapter = new FeedAdapter(FeedUtils.generateFeeds(getContext()),this);
        feed_recycler_view.setAdapter(feed_adapter);
        return view;
    }

    public static FeedFragment newInstance() {
        FeedFragment fragment = new FeedFragment();
        return fragment;
    }

    public static void applyFont(CustomTextView tv, Activity context) {
        tv.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/Quicksand-Medium.ttf"));
    }
    @Override
    public boolean onBackPressed() {
        return false;
    }

    @Override
    public void onFeedItemClick(int pos, Feed_Data_Provider feedDataProvider, AppCompatImageView shareImageView) {
        Intent intent = new Intent(getContext(), ChatActivity.class);
        intent.putExtra(EXTRA_FEED_ITEM, feedDataProvider);
        intent.putExtra(EXTRA_FEED_IMAGE_TRANSITION_NAME, ViewCompat.getTransitionName(shareImageView));

        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
                getActivity(),
                shareImageView,
                ViewCompat.getTransitionName(shareImageView));

        startActivity(intent, options.toBundle());
    }
}

这是活动代码

public class ChatActivity extends AppCompatActivity {
        AppCompatImageView chat_image;
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat);
        getWindow().setEnterTransition(null);
        Bundle extras = getIntent().getExtras();
        Feed_Data_Provider feedItem = extras.getParcelable(FeedFragment.EXTRA_FEED_ITEM);
        chat_image = (AppCompatImageView)findViewById(R.id.chat_image);
        postponeEnterTransition();
        int imageUrl =feedItem.getClub_image();
        supportPostponeEnterTransition();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            String imageTransitionName = extras.getString(FeedFragment.EXTRA_FEED_IMAGE_TRANSITION_NAME);
            if (imageTransitionName != null) {
                chat_image.setTransitionName(imageTransitionName);
            }
        }
        Glide.with(this)
                .load(imageUrl)
                .listener(new RequestListener<Drawable>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                        supportStartPostponedEnterTransition();
                        return false;

                    }

                    @Override
                    public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                        supportStartPostponedEnterTransition();
                        return false;
                    }
                })
                .into(chat_image);

    }


}

布局文件

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/event_card_view"
    android:layout_width="wrap_content"
    android:layout_height="@dimen/_200sdp"
    android:layout_marginRight="@dimen/_5sdp"
    android:layout_marginLeft="@dimen/_5sdp"
    card_view:cardUseCompatPadding="true"
    card_view:cardCornerRadius="14dp"
    android:layout_marginBottom="16dp"
    android:transitionName="@string/first_page_transition"
    card_view:cardBackgroundColor="@color/White"
    tools:targetApi="lollipop">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v7.widget.AppCompatImageView
            android:id="@+id/party_image"
            android:layout_width="@dimen/_170sdp"
            android:layout_height="@dimen/_140sdp"
            android:adjustViewBounds="true"
            android:src="@drawable/dj"

            android:scaleType="centerCrop" />

        <com.example.mapwithmarker.Custom.CustomTextViewMedium
            android:id="@+id/party_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="13sp"
            android:text="Ladies Night"
            android:textColor="@color/colorPrimary"
            android:layout_below="@+id/country_photo"
            android:paddingLeft="@dimen/_5sdp"
            android:paddingTop="8dp"
            android:layout_alignParentBottom="true"
            />
        <com.example.mapwithmarker.Custom.CustomTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="13sp"
            android:paddingLeft="@dimen/_5sdp"
            android:text="Mumbai"
            />
    </LinearLayout>

</android.support.v7.widget.CardView>

1 个答案:

答案 0 :(得分:0)

尝试在滑行时使用缓存策略。

Glide.with(this)      .load(imageUrl)      .discCacheStrategy(DiscCacheStrategy.SOURCE)