- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在开始之前,我只是想让您知道我是 Android 编程新手,所以这个问题实际上可能有点愚蠢。
在我的 mainActivity.java
文件中,我有一个使用 3 个 viewPager
fragment 的选项卡式布局:fragment1
、fragment2
、和fragment3
。
我希望当第二个 fragment 进入时窗口的背景颜色能够平滑地改变,为此我从颜色动画中得到了一个 valueAnimator:
public class fragment2 extends Fragment {
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragmentlayout2, null);
int colorFrom = getResources().getColor(R.color.white);
int colorTo = getResources().getColor(R.color.colorFrame2);
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.setDuration(250); // milliseconds
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
getView().findViewById(R.layout.fragmentlayout2).setBackgroundColor((int) animator.getAnimatedValue());
}
});
colorAnimation.start();
}
}
当我尝试运行该程序时,它返回有关 colorFrom 语句的无法访问的语句
错误。我已经尝试解决它,但它不会消失!任何帮助表示赞赏!
最佳答案
将 return
移到 onCreateView
的末尾,因为 return
会发回控件并且不会进一步
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
int colorFrom = getResources().getColor(R.color.white);
int colorTo = getResources().getColor(R.color.colorFrame2);
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.setDuration(250); // milliseconds
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
getView().findViewById(R.layout.fragmentlayout2).setBackgroundColor((int) animator.getAnimatedValue());
}
});
colorAnimation.start();
return inflater.inflate(R.layout.fragmentlayout2, null);
// ^^^^^^^^
}
关于java - colorAnimation 中无法访问的语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47331077/
我正在控件模板级别为按钮的背景设置动画,但由于初始背景颜色设置为透明,我注意到一个奇怪的效果,其中过渡从透明 => 一些白色/灰色中间 => 我想要的颜色。 这是显示效果的 gif: 按钮样式 (XA
我对彩色动画有一个奇怪的问题。 我有一个绑定(bind)到列表框的项目列表。这些项目有一个枚举属性,它可以是三个值之一 - NoRemarks、RemarksFound 和 RemarksUpdate
我想知道是否有人可以帮助我 - 我有一个标签,当在后面的代码中调用方法时,我需要能够在任何 2 种颜色之间交叉淡入淡出。 到目前为止我最好的尝试: Private OldColor as Color
在开始之前,我只是想让您知道我是 Android 编程新手,所以这个问题实际上可能有点愚蠢。 在我的 mainActivity.java 文件中,我有一个使用 3 个 viewPager fragme
我有几个类似切换的按钮,我想在按下状态时一致地跳动。 我已经定义了一种带有触发发光动画的触发器的样式,并且效果很好,除了每个按钮与其他按钮异步脉动的事实。 我怎样才能让每个按钮的脉冲与其他按钮同步?
我有一个带有 ColorAnimation 的自定义 button-style。 这很好用,但是当反复按下多次时,它会停留在目标颜色上。
嗯,我正在尝试使用 ColorAnimation 更改 DataTemplate 中 StackPanel 的背景颜色:
我无法弄清楚如何使用 ColorAnimation 沿可见光谱更改椭圆的填充颜色。 ColorAnimation 将颜色混合在一起,而不是沿着色谱移动,所以我想到了以下内容。
我想做一些看似很简单的事情,但我不知道该怎么做。我有一个 ColorAnimation,当 MouseEnter 事件发生时触发。它只是将边框的背景颜色从一种颜色更改为另一种颜色。 不幸的是,我不知道
我正在尝试使用以下 Storyboard向右滑动更改 ListView 项目的颜色,但它引发了一个异常 WinRT information: ColorAnimation cannot be used
我遇到了 ControlTemplate 的问题为 ToggleButton我创建。 当按钮为 Checked , ColorAnimation被触发并且控件的背景改变颜色。但是,如果用户输入 Mou
我试图以编程方式使用 ColorAnimation 来为单元格设置动画,但我在执行 storyboard.Begin() 时得到了这个 'System.Windows.Media.Animation.
我有一个 ListView,AlternationCount 设置为 2。我有一个 ListViewItem 样式,当前将 ListViewItem 的背景颜色设置为交替颜色,我想添加第三个触发器,它
我是一名优秀的程序员,十分优秀!