小编Ron*_*onU的帖子

如何在Android中为视图设置动画并使其保持新的位置/大小?

我目前在我的Android应用程序中有一个视图,视图正在播放帧动画.我想为视图设置动画,将其大小增加到150%.当我对其应用缩放动画并完成缩放动画时,我希望视图在活动的其余部分生命周期中保持新的大小.不幸的是,当放大动画完成时,视图会快速恢复到原始大小.我怎样才能保持新的动画转换?

我正在使用

myView.startAnimation(AnimationUtils.loadAnimation(mContext,R.anim.scaleUp150));
Run Code Online (Sandbox Code Playgroud)

谢谢!

animation android

80
推荐指数
4
解决办法
9万
查看次数

如何使Active Record连接返回唯一对象?

我有一个简单的查询需求:查找自2013年1月1日起订购的用户列表.

在SQL中,这是一个非常简单的查询.

但我正在使用Rails和Active Record.

所以我写道: User.joins(:orders).where("orders.created_at >= '2013-01-01 00:00:00'")

在我们的数据库中,我们自2013年1月1日起有75个用户发出了100个订单.(显然有些用户发了多个订单.)

但是,上面的表达式返回100个用户.(必须有重复.)

我试过了 User.joins(:orders).where("orders.created_at >= '2013-01-01 00:00:00'").uniq

这也行不通.

如何获得自2013年1月1日起订购的75位用户?

activerecord ruby-on-rails

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

Docker 1.10通过主机的主机名访问容器

我有Docker版本1.10与嵌入式DNS服务.

我在docker-compose文件中创建了两个服务容器.它们可以通过主机名和IP相互访问,但是当我想从主机到达其中一个时,它不起作用,它只适用于IP但不适用于主机名.

那么,是否可以通过Docker 1.10中的主机名从主机访问docker容器,好吗?

更新:

泊坞窗,compose.yml

version: '2'
services:
    service_a:
        image: nginx
        container_name: docker_a
        ports:
           - 8080:80
    service_b:
        image: nginx
        container_name: docker_b
        ports:
            - 8081:80
Run Code Online (Sandbox Code Playgroud)

然后我按命令启动它: docker-compose up --force-recreate

当我跑:

  • docker exec -i -t docker_a ping -c4 docker_b - 有用
  • docker exec -i -t docker_b ping -c4 docker_a - 有用
  • ping 172.19.0.2- 它的工作原理(172.19.0.2docker_b的)
  • ping docker_a- 失败了

结果docker network inspect test_default

[
    {
        "Name": "test_default",
        "Id":   "f6436ef4a2cd4c09ffdee82b0d0b47f96dd5aee3e1bde068376dd26f81e79712",
        "Scope": "local",
        "Driver": "bridge",
        "IPAM": { …
Run Code Online (Sandbox Code Playgroud)

docker docker-compose docker-networking

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

当ID存在时,获取"表的未知主键"

我一直在调试这个Rails的奇怪问题,给我"桌面的未知主键......",即使桌子的ID在那里.

我已经将数据库从一个heroku应用程序复制到另一个,在原始数据库上没有问题,新的一个给了我一个db错误.

这是错误:

ProductsController# (ActionView::Template::Error) "Unknown primary key for table collections in model Collection."

/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/reflection.rb:366:in `primary_key'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/reflection.rb:480:in `association_primary_key'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/associations/association_scope.rb:58:in `block in add_constraints'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/associations/association_scope.rb:39:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/associations/association_scope.rb:39:in `each_with_index'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/associations/association_scope.rb:39:in `add_constraints'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/associations/association_scope.rb:31:in `scope'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/associations/association.rb:98:in `association_scope'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/associations/association.rb:87:in `scoped'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/associations/collection_association.rb:573:in `first_or_last'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/associations/collection_association.rb:105:in `last'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/associations/collection_proxy.rb:46:in `last'
/app/app/helpers/likes_helper.rb:62:in `significant_liker'
Run Code Online (Sandbox Code Playgroud)

引起它的那条线:

product.collections.last.try :user
Run Code Online (Sandbox Code Playgroud)

和表:

d8apjspa441pad=> \d collections
                                     Table "public.collections"
     Column     |          Type          |                        Modifiers                         
----------------+------------------------+----------------------------------------------------------
 id             | integer                | not null default nextval('collections_id_seq'::regclass)
 name           | character varying(255) | 
 user_id        | integer                | 
 permalink      | character varying(255) | 
 category_id …
Run Code Online (Sandbox Code Playgroud)

postgresql ruby-on-rails heroku rails-activerecord heroku-postgres

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

如何使用Dagger为活动和片段以外的东西设置依赖注入?

我开始使用Dagger设置依赖注入,如下所示.因为我可能有错误,所以请鼓励我更正我的实施!该实现遵循项目提供的android-simple示例.在下面你可以看到我是如何成功添加依赖注入ActivitiesFragments.我现在试着保持简单,所以我决定将Timber注入Android的log util的记录器替换.

import android.app.Application;
import java.util.Arrays;
import java.util.List;
import dagger.ObjectGraph;
import com.example.debugging.LoggingModule;

public class ExampleApplication extends Application {

    private ObjectGraph mObjectGraph;

    protected List<Object> getModules() {
        return Arrays.asList(
                new AndroidModule(this),
                new ExampleModule(),
                new LoggingModule()
        );
    }

    private void createObjectGraphIfNeeded() {
        if (mObjectGraph == null) {
            Object[] modules = getModules().toArray();
            mObjectGraph = ObjectGraph.create(modules);
        }
    }

    public void inject(Object object) {
        createObjectGraphIfNeeded();
        mObjectGraph.inject(object);
    }
}
Run Code Online (Sandbox Code Playgroud)

到现在AndroidModule没有任何地方使用,但可能会有所帮助时,ContextLayoutInflater …

android dependency-injection android-contentprovider android-asynctask dagger

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

Android应用程序名称的最大长度是多少?

我的android应用程序名称长三个字,但是当我把它放在手机中它变成两个字长.怎么解决这个?我看到许多应用程序有三个单词的例子:"高级任务杀手"

android

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

Rails 3:在活动记录中存储会话(不是cookie)

我拖了谷歌大学大约一个小时左右,但没有一个关于这个主题的好文档:-(希望有人可以提供帮助.我愿意买一本书,只要有人能告诉我哪一本.

我使用以下版本:

  • rails 3.2.6,
  • ruby 1.9.3p194(2012-04-20修订版35410)[x86_64-darwin11.4.0]

要开始在Active Record中使用会话存储而不是cookie,我做了以下操作:

  1. 更新config/initializers/session_store.rb. 评论第一行并取消注释最后一行,所以我有:

    # Be sure to restart your server when you modify this file.
    
    # Myapp::Application.config.session_store :cookie_store, key: '_elegato_session'
    
    # Use the database for sessions instead of the cookie-based default,
    # which shouldn't be used to store highly confidential information
    # (create the session table with "rails generate session_migration")
    Myapp::Application.config.session_store :active_record_store
    
    Run Code Online (Sandbox Code Playgroud)
  2. rake db:sessions:create

    invoke  active_record
      create    db/migrate/20120729025112_add_sessions_table.rb
    
    Run Code Online (Sandbox Code Playgroud)
  3. rake db:migrate

    ==  CreateLinkedinUsers: migrating ============================================
    -- create_table(:linkedin_users)
      -> 0.0236s
    ==  CreateLinkedinUsers: migrated …
    Run Code Online (Sandbox Code Playgroud)

session ruby-on-rails

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

无法推断JAVA 8的功能接口类型

我有一个工厂(注册表DP)初始化类:

public class GenericFactory extends AbstractFactory {

    public GenericPostProcessorFactory() {
        factory.put("Test",
                defaultSupplier(() -> new Test()));
        factory.put("TestWithArgs",
                defaultSupplier(() -> new TestWithArgs(2,4)));
    }

}

interface Validation

Test implements Validation
TestWithArgs implements Validation
Run Code Online (Sandbox Code Playgroud)

并在AbstractFactory中

 protected Supplier<Validation> defaultSupplier(Class<? extends Validation> validationClass) {
        return () -> {
            try {
                return validationClass.newInstance();
            } catch (InstantiationException | IllegalAccessException e) {
                throw new RuntimeException("Unable to create instance of " + validationClass, e);
            }
        };
    }
Run Code Online (Sandbox Code Playgroud)

但我不断得到无法推断功能接口类型错误.我在这做错了什么?

java registry lambda java-8

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

为什么果冻豆不会在通知中显示第二行?

我目前正在研究Android Support Package v4 Rev 10的NotificationCompat功能.文档说'setContentText()'显示通知中的第二行.这适用于API 8直到API 15.但是,如果我尝试在API 16中使用此方法,我的通知将错过第二行.我只看到标题而不是第二行.添加多行是没有问题的(使用'addline()').

这是我使用的NotificationCompat.Builder的代码:

private NotificationCompat.Builder buildNormal(CharSequence pTitle) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(
            getSherlockActivity());

    builder.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL);
    // set the shown date
    builder.setWhen(System.currentTimeMillis());
    // the title of the notification
    builder.setContentTitle(pTitle);
    // set the text for pre API 16 devices
    builder.setContentText(pTitle);
    // set the action for clicking the notification
    builder.setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS));
    // set the notifications icon
    builder.setSmallIcon(android.R.drawable.stat_sys_download_done);
    // set the small ticker text which runs in the tray for a few seconds
    builder.setTicker("This is your …
Run Code Online (Sandbox Code Playgroud)

notifications android android-4.2-jelly-bean

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

docker health check 中的多个健康检查卷曲

为了确保容器的健康检查,我需要对多个 URL 执行测试调用。

curl -f http://example.comcurl -f http://example2.com

是否可以执行多个curl 调用来进行docker 健康检查?

docker health-check

7
推荐指数
2
解决办法
8424
查看次数