如何使用setOutlineProvider代替setOutline在棒棒糖 [英] How to use setOutlineProvider instead of setOutline in Lollipop

查看:2795
本文介绍了如何使用setOutlineProvider代替setOutline在棒棒糖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关早期的大号preVIEW有一些例子如下所示添加到您的code,以使用FAB(浮动操作按钮)。

但遗憾的是我不能用同样的code实现的FAB,由于没有被支持了,但它似乎已经取代了另一种方法setOutline法fab.setOutlineProvider(ViewOutlineProvider); 。任何人都可以解释如何使用呢?...

这可能是很简单的东西,我很想念,但任何帮助将是非常美联社preciated。

  //大纲
INT大小= getResources()getDimensionPixelSize(R.dimen.fab_size)。
概述概述=新纲要();
outline.setOval(0,0,大小,尺寸);

按钮FAB =(按钮)findViewById(R.id.fab);
fab.setOutline(提纲)​​;
fab.setClipToOutline(真正的);
 

解决方案

只是为了完成@ianhanniballake答案:

 按钮FAB =(按钮)findViewById(R.id.fab);
//外形轮廓=新纲要();
//outline.setOval(0,0,大小,尺寸);
//fab.setOutline(outline);
ViewOutlineProvider viewOutlineProvider =新ViewOutlineProvider(){
        @覆盖
        公共无效getOutline(查看视图,外形轮廓){
            //或者直接从视图的宽/高读取大小
            INT大小= getResources()getDimensionPixelSize(R.dimen.fab_size)。
            outline.setOval(0,0,大小,尺寸);
        }
    };
fab.setOutlineProvider(viewOutlineProvider);
 

For the earlier L Preview there were some examples like shown below to add to your code in order to use an FAB (Floating Action Button).

But unfortunately I can't use that same code to implement an FAB due to the setOutline method not being supported anymore, but it appears to have been replaced by an alternative method 'fab.setOutlineProvider(ViewOutlineProvider);'. could anyone explain how to use this?...

It is probably something really simple that I am missing, but any help would be much appreciated.

// Outline
int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
Outline outline = new Outline();
outline.setOval(0, 0, size, size);

Button fab = (Button) findViewById(R.id.fab);
fab.setOutline(outline);
fab.setClipToOutline(true);

解决方案

Just to complete the @ianhanniballake answer:

Button fab = (Button) findViewById(R.id.fab);
//Outline outline = new Outline();
//outline.setOval(0, 0, size, size);
//fab.setOutline(outline);  
ViewOutlineProvider viewOutlineProvider = new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            // Or read size directly from the view's width/height
            int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
            outline.setOval(0, 0, size, size);
        }
    };
fab.setOutlineProvider(viewOutlineProvider);

这篇关于如何使用setOutlineProvider代替setOutline在棒棒糖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆