小编Sli*_*ind的帖子

WindsorContainers AddChildContainer 真的有这么糟糕吗?

我正在尝试从一组基本注册中分支出多个子容器,以便于进行不同的配置设置。

我认为根据Mark Seemanns 关于子容器如何工作的回复,我可以使用子容器来覆盖基本注册中的特定组件。然而我似乎并不像西曼所说的那样工作。

根据马克的说法,这应该有效:

[TestMethod]
public void OverrideRegistrationInParentContainer()
{
    //IBusinessComponent depends on IBasicComponent
    var parentContainer = new WindsorContainer();
    parentContainer.Register(Component.For<IBasicComponent>().ImplementedBy<BasicComponent>()); //Returns 42
    parentContainer.Register(Component.For<IBusinessComponent>().ImplementedBy<RealBusinessComponent>()); //Returns the result of IBasicComponent


    var childContainer = new WindsorContainer();
    childContainer.Register(Component.For<IBasicComponent>().ImplementedBy<BasicComponent2>()); //Returns 40

    parentContainer.AddChildContainer(childContainer);

    var service = childContainer.Resolve<IBusinessComponent>();
    Assert.AreEqual(40, service.GetBusinessValue()); //This fails with the actual value being 42
}
Run Code Online (Sandbox Code Playgroud)

然而,所有依赖关系显然都是从父级解决的。

如果我从parentContainer 中删除IBasicComponent 注册,由于缺少注册,我什至无法解决依赖关系。

谁能解释一下如何让容器像 Seemann 声称的那样运行,或者 WindsorContainer 真的无法以优雅的方式处理这种类型的配置吗?

castle-windsor ioc-container

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

如何在ListView中为单个元素设置动画

我正在做一个基于ListView的小型Android应用程序.当用户选择列表中的一个或多个元素并随后从ActionBar中选择一个菜单项时,我想对列表中的选定元素执行一个小动画,这就是出错的地方.

什么都没有动画 - 也没有任何失败.以下代码片段是我正在做的简化版本:

private void animateListViewItem()
{
    TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f);
    anim.setDuration(2000);
    View v = fragment.getListAdapter().getView(fragment.getListView().getFirstVisiblePosition(), null, null);
    v.startAnimation(anim);
}
Run Code Online (Sandbox Code Playgroud)

当我搞砸了它,试图弄清楚什么是错的时候,我在某一点上用整个ListView替换了项目以排除动画作为问题的根源 - 就像这样.

private void animateListViewItem()
{
    TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f);
    anim.setDuration(2000);
    fragment.getListView().startAnimation(anim);
}
Run Code Online (Sandbox Code Playgroud)

令我惊讶的是,这完美无缺!

所以我的问题是 - 为什么我不能动画ListView中的各个元素?或者我做错了什么?

谢谢!

PS为了记录,ListView填充了自定义视图(LinearLayouts),我已经检查过我在动画制作之前得到了正确的项目.

animation android listview

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