标签: android-animation

找不到具有此名称的参数:指示

您好,我正在尝试在 compose 中绘制 Canvas ..但是当我在 Modifier.clickable() 中使用指示参数时,我收到此错误 Cannot find a parameter with this name: indication

\n

代码:

\n
@Composable\nfun MiniFloatingActionButton(item: MultiFabItem, onFabItemClicked: (item: MultiFabItem) -> Unit) {\n    Canvas(\n        modifier = Modifier.size(32.dp)\n            .clickable(\n                onClick = { onFabItemClicked(item) },\n                //Cannot find a parameter with this name: indication\n                indication = rememberRipple(\n                    bounded = false,\n                    radius = 20.dp,\n                    color = MaterialTheme.colors.onSecondary\n                )\n            )\n    ) {\n//        \xe2\x80\xa6\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

android android-animation kotlin floating-action-button android-jetpack-compose

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

在 Compose 中无限且反向地制作线性渐变(画笔)动画

初始状态看起来像这样 ( animatedOffset = 0f)

在此输入图像描述

我想得到1f反向梯度:

![在此输入图像描述

当前代码:

val transition = rememberInfiniteTransition(label = "NavIconGradientAnim")

val animatedOffset by transition.animateFloat(
    initialValue = 0f, targetValue = 1f,
    label = "NavIconGradientAnimOffset",
    animationSpec = infiniteRepeatable(
        animation = tween(1500, easing = LinearEasing),
        repeatMode = RepeatMode.Reverse
    )
)
Image(
    painterResource(id = item.icon),
    contentDescription = null,
    modifier = Modifier.drawWithCache {
        onDrawWithContent {
            with(drawContext.canvas.nativeCanvas) {
                val angle = 45f
                val endX = drawContext.size.width
                val endY = (endX * kotlin.math.tan(Math.toRadians(angle.toDouble()))).toFloat()

                val checkPoint = saveLayer(null, null)
                drawContent()
                val gradient …
Run Code Online (Sandbox Code Playgroud)

android android-animation android-jetpack-compose jetpack-compose-animation android-jetpack-compose-animation

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

为Android应用程序设计动画

设计和嵌入动画到Android应用程序的最佳方法是什么.(我不是在谈论动画中的过渡和活动.)

我可以想到两种方法:

  1. 使用flash或类似设计动画,使用透明bgs导出png-sequence并从xml文件中的图像创建动画(如何编写这种xml?)
  2. 使用我创建的动画的所有帧创建图像网格并将其保存到一个图像中.比在css中使用像background-position这样的东西来移动每个帧上的图像的可见区域(通过Java代码,或通过xml)

哪个更好/最常见?以及如何实施解决方案(如果有更好的解决方案 - 那会很棒).你通常用什么程序来完成这类任务

(目标是实现像青蛙一样切割绳子或愤怒的小鸟中的鸟类)

谢谢!

mobile android android-animation android-layout

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

将android:layoutAnimation添加到LinearLayout会导致FC

我在menu.xml中有以下XML,它是一个我需要设置动画的LinearLayout,所以我使用了layoutAnimation属性.如果没有这个属性,布局会显示出来,但是有了这个属性集我会得到一个令人讨厌的forceclose,我不明白为什么:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bkgrnd"
    android:layoutAnimation="@anim/menu_anim" <=== adding this results in FC
...etc...
Run Code Online (Sandbox Code Playgroud)

动画/ menu_anim.xml:

<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:duration="500">
    </alpha>    

</set>
Run Code Online (Sandbox Code Playgroud)

请帮忙!谢谢!

android-animation forceclose

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

R.anim.slide_left_in和R.anim.slide_left_out之间有什么不同

什么是不同之间 R.anim.slide_left_inR.anim.slide_left_out也, R.anim.slide_right_inR.anim.slide_right_out
我有以下XML进行slide_left_in

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <translate
        android:duration="700"
        android:fromXDelta="-100%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="0%" />

</set>
Run Code Online (Sandbox Code Playgroud)

xml android android-animation

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

Android ListView OnItemClick动画

我有这个ListView从Facebook获取朋友:

@Override
        public void onComplete(List<Profile> friends) {

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mSpinner.setVisibility(View.GONE);
                    mSpinner.clearAnimation();
                }
                });

            // populate list
            List<String> values = new ArrayList<String>();
            for (Profile profile : friends) {
                values.add(profile.getName());
            }



            ArrayAdapter<String> friendsListAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.list_items2, values);
            friendsListAdapter.sort(new Comparator<String>() {
                @Override
                public int compare(String lhs, String rhs) {
                    return lhs.compareTo(rhs);    
                }
            });
            mFriendsList.setAdapter(friendsListAdapter);
        }
    };
Run Code Online (Sandbox Code Playgroud)

而且我有这个动画xml:

<set xmlns:android="http://schemas.android.com/apk/res/android">
 <translate android:fromXDelta="100%p" android:toXDelta="0"
     android:duration="300"/>
   <alpha android:fromAlpha="0.0" android:toAlpha="1.0"
     android:duration="300" />
</set>
Run Code Online (Sandbox Code Playgroud)

我试图寻找有关如何将动画添加到ListView的示例,但是我无法让它们与我的代码一起使用,我想创建的是当单击ListView中的项目时,它将启动动画。如何使用OnItemClick将其添加到代码中?

android android-animation android-listview

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

使用CollapsingToolbarLayout在嵌套布局中破坏Animate布局更改

我的活动中有以下布局:

CoordinatorLayout ?? AppBarLayout ? ?? CollapsibleToolbarLayout ? ?? TextView (parallax) ? ?? TextView (pin) ? ?? Toolbar ?? NestedScrollView ?? LinearLayout ?? TextView 1 ?? LinearLayout 1 ? ?? 1 to n Views (dynamically added/removed) ... ?? TextView n ?? LinearLayout n ?? 1 to n Views (dynamically added/removed)

当我将Layouts中的animateLayoutChanges设置为true时,无论何时在NestedScrollView内部发生布局更改,结果布局都会与AppBarLayout的内容重叠.

我尝试了这个stackoverflow评论中的建议,但它没有帮助.

有没有人有类似/相同的问题,并找到了解决方案?

android android-animation android-layout android-collapsingtoolbarlayout android-appbarlayout

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

RecyclerView | 最快的smoothScrollToPosition动画

问题是基于真实场景,我简化了用例:

假设我们有一个带有0到999之间值的微调器和循环视图.另外,对于常规的回收者滑动选项,用户也可以从微调器中选择一个数字,并且回收器将滚动到索引.

问题:当当前页面和新的微调器值之间的差值很大时,滚动视图需要花费大量时间(例如,我们在位置0,现在用户从微调器400中选择).

下面是代码(项目布局仅包含textview):

public class MainActivity extends AppCompatActivity {
    RecyclerView recyclerView;
    Spinner spinner;
    List<Integer> items = new ArrayList<>();
    ItemAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // init "database"
        for (int i = 0; i < 1000; i++)
            items.add(i);

        // Spinner
        spinner = (Spinner) findViewById(R.id.spinner);
        final ArrayAdapter<Integer> spinnerAdapter = new ArrayAdapter<Integer>(this, R.layout.support_simple_spinner_dropdown_item, items);
        spinner.setAdapter(spinnerAdapter);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                recyclerView.smoothScrollToPosition(i);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) …
Run Code Online (Sandbox Code Playgroud)

android android-animation recycler-adapter android-recyclerview

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

Android:如何选择RotateAnimation的旋转方向?

我目前正在开发一个应用程序,其中我想用箭头指示一个路径(它像指南针一样工作).

为了将箭头移动到好的方向,我使用了这个RotateAnimation类.它工作得很好但是当初始度数位置远离最终度数位置时,旋转不会选择更快的方式.

在此视频中,您可以看到以下行为:https://youtu.be/vypZni_1s3I

这里是用户单击按钮"02"时执行的代码:

RotateAnimation rotateAnimation = new RotateAnimation(355f, 8f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setDuration(3000);
rotateAnimation.setFillAfter(true);
test.startAnimation(rotateAnimation);
Run Code Online (Sandbox Code Playgroud)

这里是用户单击按钮"03"时执行的代码:

RotateAnimation rotateAnimation = new RotateAnimation(8f, 350f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setDuration(3000);
rotateAnimation.setFillAfter(true);
test.startAnimation(rotateAnimation);
Run Code Online (Sandbox Code Playgroud)

正如您在视频中看到的那样,旋转不会选择更快的方式.在第一个动画中,更快的方法是顺时针旋转(但系统选择逆时针旋转),在第二个动画中,更快的方法是逆时针旋转(但系统选择顺时针旋转).

是否有解决方案或技巧迫使系统选择更快的方式从A点旋转到B点?

animation android rotation android-animation

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

安卓 重力变化动画

我在另一个框架内。它与中心对齐。

不,我想通过更改其重力使其与顶部对齐,但我也想为该更改设置动画。

我已经在这里/sf/answers/2323463481/找到了这个答案,但是在那里使用LayoutTransition.CHANGING需要API 16。

但是我们的应用程序的minSdk是14。关于如何设置重力变化的动画的建议吗?

先感谢您

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

    <ImageView
        android:id="@+id/background"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/bg"
        android:scaleType="centerCrop"/>

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:animateLayoutChanges="true">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            android:src="@drawable/container_bg"/>
        <EditText
            android:layout_gravity="center_vertical"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"/>
    </FrameLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

android android-animation

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