标签: android-animation

动画删除ListView项

我正在尝试使用以下方法动画删除ListView项:

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, final View view, final int i, long l) {
            view.animate().setDuration(500).x(-view.getWidth()).alpha(0f);
            adapter.remove(tasks.get(i));
            adapter.notifyDataSetChanged();
        }
    });
Run Code Online (Sandbox Code Playgroud)

这是行不通的.我基本上遵循了这篇文章顶部第四个答案的建议:

如何动画添加或删除Android ListView行

然而,有一些有趣的绘图内容正在进行,或回收,或者某些东西,因为在动画发生时,屏幕滑落的项目下方的项目也会因某种原因被删除.不幸的是,问题提示者最终标记为正确的答案是整个Android来源的RTFM.我已经浏览了那里,我无法在JellyBean中找到我正在尝试模拟的通知下拉.

TIA.约翰

android android-animation android-layout android-listview

31
推荐指数
2
解决办法
3万
查看次数

如何使用九个旧的机器人动画创建ImageView脉冲效果

我想知道如何使用九个olad架构动画创建一个脉冲效果.

为了更好地理解你可以说你有一个ImageView,并希望有一个"脉冲"效果,如使图像小一点,然后回到原始大小,缩放将居中.

我使用九个olad机器人向后兼容.

欢迎任何其他选择.

谢谢.

android android-animation android-imageview

30
推荐指数
3
解决办法
3万
查看次数

Android列表视图右/左滑动,如通话记录

我有一个Android应用程序,其中有List View就像这个

在此输入图像描述

现在,我想以相同的方式对列表项的右/左滑动执行两个不同的活动本机调用日志的工作原理

右键滑动清单

在此输入图像描述

我想要这种类型的滑动.任何人都可以知道如何实现它.基本上我想实施SimpleOnGestureListener.

我已经阅读了sir gav 回答的帖子在网格布局上回答了手势检测,之后我成功实现了左滑动和右滑动检测,但我唯一没有看到滑动发生在哪个List Item上.

2013年5月24日更新

现在我可以使用此代码检测滑动操作 -

SwipeDetector.java

/**
 * Class swipe detection to View
 */
public class SwipeDetector implements View.OnTouchListener {

    public static enum Action {
        LR, // Left to right
        RL, // Right to left
        TB, // Top to bottom
        BT, // Bottom to top
        None // Action not found
    }

    private static final int HORIZONTAL_MIN_DISTANCE = 30; // The minimum
    // distance for
    // …
Run Code Online (Sandbox Code Playgroud)

android listview swipe android-animation android-layout

30
推荐指数
2
解决办法
3万
查看次数

如何在Android中的ObjectAnimator中给出百分比值

我正在使用objectAnimator在Android中从下到上动画一个按钮.现在我使用下面的代码

ObjectAnimator transAnimation = ObjectAnimator.ofFloat(button,"translationY",0,440);
        transAnimation.setDuration(440);
        transAnimation.start();
Run Code Online (Sandbox Code Playgroud)

我也试过下面的示例代码.但问题仍然存在

ObjectAnimator transAnimation = ObjectAnimator.ofFloat(loginLayout, "translationY",0f,0.8f);
                    transAnimation.setDuration(480);
                    transAnimation.start();
Run Code Online (Sandbox Code Playgroud)

它适用于大屏幕设备.但是当谈到小屏幕设备时,它就会离开屏幕.无论屏幕大小不同,我都希望将其保留在屏幕顶部.我想我必须给出百分比值(比如0%到100%或0到100%p).所以我的问题是如何在Android中的objectAnimator中给出百分比值.我还注意到这个objectAnimator只在HoneyComb中引入了一件事.那么是否有任何向后兼容库可以在低版本中运行它.任何人都可以指导我找到解决方案.

我也试过扩展View并为该属性编写getter和setter offset().它仍然没有完全移动到屏幕顶部.这是我用过的代码.

@SuppressLint("NewApi") public float getXFraction()
    {
        int width = context.getWindowManager().getDefaultDisplay().getHeight();
        return (width == 0) ? 0 : (getY());
    }

    @SuppressLint("NewApi") public void setXFraction(float xFraction) {
        int width = context.getWindowManager().getDefaultDisplay().getWidth();
        setY((width > 0) ? (width) : 0);
    }
Run Code Online (Sandbox Code Playgroud)

提前致谢

android android-animation objectanimator

29
推荐指数
1
解决办法
2万
查看次数

在ImageView上单击从下到上和从上到下的Android布局动画

我在Android中创建了一个视图,我需要从下到上为其设置动画,反之亦然.当我点击时,ImageView我需要RelativeLayout从底部到顶部动画完整,并且它成功了.但是,当我再次点击ImageView它并没有向下移动时.此外,当我点击其原始位置时,当我单击ImageView动画的原始位置时,但从RelativeLayout原始位置向下移动而不是从上到下.

这是我的代码:

ImageView iv_header;

RelativeLayout rl_footer;

boolean isBottom = true;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.rateus_layout);
    rl_footer = (RelativeLayout) findViewById(R.id.rl_footer);
    iv_header = (ImageView) findViewById(R.id.iv_up_arrow);

    iv_header.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (isBottom) {
                FooterAnimation();
                isBottom = false;
            } else {
                headerAnimation();
                isBottom = true;
            }

        }
    });
}

public void FooterAnimation() {
    Animation hide = …
Run Code Online (Sandbox Code Playgroud)

android android-animation

29
推荐指数
4
解决办法
10万
查看次数

在FragmentManager上调用popBackStack时的customAnimation

在我的活动中,只需按一下按钮,我就会使用自定义动画将新片段替换为当前片段,如本例所示.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
        case R.id.action_anomalie:
            Fragment contentFragment = getFragmentManager().findFragmentById(R.id.content);

            if(contentFragment instanceof AnomalieListFragment)
            {
                getFragmentManager().popBackStack();
                return true;
            }
            else
            {
                FragmentTransaction ft = getFragmentManager().beginTransaction();
                ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
                anomalieFragment = new AnomalieListFragment();
                ft.replace(R.id.content, anomalieFragment);
                ft.addToBackStack(null);
                ft.commit();
            }

    ...
Run Code Online (Sandbox Code Playgroud)

但是,弹回堆栈不会显示任何动画.有没有办法像使用setCustomAnimations方法一样在FragmentTransaction中指定自定义动画?

android android-animation android-fragments

29
推荐指数
1
解决办法
1万
查看次数

Android:如何拍出漂亮的心跳动画?

这是我的解决方案

动画/ pulse.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
    android:duration="300"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:repeatMode="reverse"
    android:toXScale="0.75"
    android:toYScale="0.75"
    android:interpolator="@android:interpolator/bounce" />
<scale
    android:duration="100"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:repeatMode="reverse"
    android:toXScale="1.25"
    android:toYScale="1.25"
    android:interpolator="@android:interpolator/bounce" />
 </set>
Run Code Online (Sandbox Code Playgroud)

然后在activity.java中:

ImageView imageView = (ImageView) findViewById(R.id.image);
imageView.startAnimation(AnimationUtils.loadAnimation(this, R.anim.pulse));
Run Code Online (Sandbox Code Playgroud)

我不满意,因为真正的跳动的心脏有更优雅的收缩.怎么可以改进?

编辑:我认为一个很好的效果会模仿心跳.快速收缩然后是另一个收缩.也许最后一局在上半场可能很快,然后在下半场慢慢逆转.有没有办法让所有这些效果相互引发?

xml animation android android-animation objectanimator

29
推荐指数
0
解决办法
1万
查看次数

从左到右模式启动活动

我正面临一个问题.

我有三个活动,我需要开始左侧滑动的新活动.

Activity1

Activity2

Activity3
Run Code Online (Sandbox Code Playgroud)

手段 在此输入图像描述

当我点击按钮时,新活动不应该像android行为一样直接显示.

我想要从右侧进行新活动并在当前屏幕上显示.

任何人都可以提供指导.这是动画或其他任何东西.

android android-animation

28
推荐指数
4
解决办法
5万
查看次数

RecyclerView无法按预期滚动

我有一个项目,我使用水平回收视图,我想中心一个元素.我的实现有效,但不是在每种情况下都可以在这里检查这个GIF:

你可能会注意到,如果我从左边来,它会正确滚动.如果我来自右边它会过度滚动,我不知道如何停止或如何解决这个问题.

我在这里将代码条带化为此示例:

public class DemoActivity extends ActionBarActivity implements View.OnClickListener {
    private static final int JUMP_TO_LEFT = MyAdapter.NON_VISIBLE_ITEMS + MyAdapter.VISIBLE_ITEMS - 1;
    private static final int JUMP_TO_RIGHT = MyAdapter.NON_VISIBLE_ITEMS;
    private LinearLayoutManager mLayoutManager;
    private RecyclerView mRecycler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo);
        findViewById(android.R.id.button1).setOnClickListener(this);
        mRecycler = (RecyclerView)findViewById(R.id.recycler);
        MyAdapter mAdapter = new MyAdapter();
        mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
        mRecycler.setLayoutManager(mLayoutManager);
        mRecycler.setHasFixedSize(true);
        mRecycler.scrollToPosition(MyAdapter.NON_VISIBLE_ITEMS);
        mRecycler.setAdapter(mAdapter);
    }

    @Override
    public void onClick(View v) {
        int pos = mLayoutManager.findFirstVisibleItemPosition();
        int outer = (MyAdapter.VISIBLE_ITEMS - 1) / …
Run Code Online (Sandbox Code Playgroud)

android smooth-scrolling android-animation android-recyclerview

28
推荐指数
2
解决办法
3万
查看次数

如何为导航操作定义默认动画?

我正在使用Android Studio 3.2 Canary 14和导航架构组件.使用此功能,您可以像使用Intent一样定义过渡动画.

但是动画被设置为导航图中动作的属性,如下所示:

<fragment
    android:id="@+id/startScreenFragment"
    android:name="com.example.startScreen.StartScreenFragment"
    android:label="fragment_start_screen"
    tools:layout="@layout/fragment_start_screen" >
  <action
    android:id="@+id/action_startScreenFragment_to_findAddressFragment"
    app:destination="@id/findAddressFragment"
    app:enterAnim="@animator/slide_in_right"
    app:exitAnim="@animator/slide_out_left"
    app:popEnterAnim="@animator/slide_in_left"
    app:popExitAnim="@animator/slide_out_right"/>
</fragment>
Run Code Online (Sandbox Code Playgroud)

为图表中的所有操作定义这一过程非常繁琐!

有没有办法在动作上将一组动画定义为默认值?

我没有运气使用款式.

android android-animation android-jetpack android-architecture-navigation

28
推荐指数
2
解决办法
3610
查看次数