English 中文(简体)
c 包括: Factor, PorterDuff.Mode.MULTIPLY; with relative Factor 0-100%
原标题:setColorFilter(relativeFactor, PorterDuff.Mode.MULTIPLY); with relative Factor 0-100%

我知道如何使用<代码>ColorFilter(colorX, PorterDuff.Mode)。 缩略语 X的定义为00000至0xFFFFFF。

但是,如果我从0到100年有价值,并试图改变这些价值观,我就能够这样做。 (100 表示100%的透明度)

这是我所尝试的——一步步——但并没有工作:

float x1 = (float) ((100 - x) / 100.0);
float x2 = x1 * 0xFFFFFFFF;
int relativeFactor = (int) x2;
Btn1.getBackground().setColorFilter(relativeFactor, PorterDuff.Mode.MULTIPLY);

What is wrong here? Many thanks!

最佳回答

你的原有守则有好有坏,而且你正在走过路;你需要投放和使用一些<>条码>。

float x2 = x1 * (float)0x0FFFFFFFFL;
long relativeFactor = (long) x2 & 0X0FFFFFFFFL;

Here s a solution that doesn t resort to floating-point:

public static void main(String[] args) {
    // TODO Auto-generated method stub
    final long onepct = 0x0FFFFFFFFL/100L;
    final long error = 0x0FFFFFFFFL-(100*onepct);
    System.out.println("onepct=" + Long.toString(onepct,16) + ",error=" + Long.toString(error,16));
    for (int x = 0; x <= 100; x++) {
        final long x2 = 0x0FFFFFFFFL - onepct*x;
        final long relativeFactor = (long) x2 & 0xFFFFFFFF;
        System.out.println("x=" + x + ", x2=" + x2 + ", rf=" + Long.toString(relativeFactor, 16));
    }
}

It is off by 95 at the low end; you can test for that if you need zero. Feel free to actually dump the values....

onepct=28f5c28,error=5f
x=0, x2=4294967295, rf=ffffffff
x=1, x2=4252017623, rf=fd70a3d7
x=2, x2=4209067951, rf=fae147af
x=3, x2=4166118279, rf=f851eb87
x=4, x2=4123168607, rf=f5c28f5f
x=5, x2=4080218935, rf=f3333337
x=6, x2=4037269263, rf=f0a3d70f
x=7, x2=3994319591, rf=ee147ae7
x=8, x2=3951369919, rf=eb851ebf
x=9, x2=3908420247, rf=e8f5c297
x=10, x2=3865470575, rf=e666666f
x=11, x2=3822520903, rf=e3d70a47
x=12, x2=3779571231, rf=e147ae1f
x=13, x2=3736621559, rf=deb851f7
x=14, x2=3693671887, rf=dc28f5cf
x=15, x2=3650722215, rf=d99999a7
x=16, x2=3607772543, rf=d70a3d7f
x=17, x2=3564822871, rf=d47ae157
x=18, x2=3521873199, rf=d1eb852f
x=19, x2=3478923527, rf=cf5c2907
x=20, x2=3435973855, rf=ccccccdf
x=21, x2=3393024183, rf=ca3d70b7
x=22, x2=3350074511, rf=c7ae148f
x=23, x2=3307124839, rf=c51eb867
x=24, x2=3264175167, rf=c28f5c3f
x=25, x2=3221225495, rf=c0000017
x=26, x2=3178275823, rf=bd70a3ef
x=27, x2=3135326151, rf=bae147c7
x=28, x2=3092376479, rf=b851eb9f
x=29, x2=3049426807, rf=b5c28f77
x=30, x2=3006477135, rf=b333334f
x=31, x2=2963527463, rf=b0a3d727
x=32, x2=2920577791, rf=ae147aff
x=33, x2=2877628119, rf=ab851ed7
x=34, x2=2834678447, rf=a8f5c2af
x=35, x2=2791728775, rf=a6666687
x=36, x2=2748779103, rf=a3d70a5f
x=37, x2=2705829431, rf=a147ae37
x=38, x2=2662879759, rf=9eb8520f
x=39, x2=2619930087, rf=9c28f5e7
x=40, x2=2576980415, rf=999999bf
x=41, x2=2534030743, rf=970a3d97
x=42, x2=2491081071, rf=947ae16f
x=43, x2=2448131399, rf=91eb8547
x=44, x2=2405181727, rf=8f5c291f
x=45, x2=2362232055, rf=8cccccf7
x=46, x2=2319282383, rf=8a3d70cf
x=47, x2=2276332711, rf=87ae14a7
x=48, x2=2233383039, rf=851eb87f
x=49, x2=2190433367, rf=828f5c57
x=50, x2=2147483695, rf=8000002f
x=51, x2=2104534023, rf=7d70a407
x=52, x2=2061584351, rf=7ae147df
x=53, x2=2018634679, rf=7851ebb7
x=54, x2=1975685007, rf=75c28f8f
x=55, x2=1932735335, rf=73333367
x=56, x2=1889785663, rf=70a3d73f
x=57, x2=1846835991, rf=6e147b17
x=58, x2=1803886319, rf=6b851eef
x=59, x2=1760936647, rf=68f5c2c7
x=60, x2=1717986975, rf=6666669f
x=61, x2=1675037303, rf=63d70a77
x=62, x2=1632087631, rf=6147ae4f
x=63, x2=1589137959, rf=5eb85227
x=64, x2=1546188287, rf=5c28f5ff
x=65, x2=1503238615, rf=599999d7
x=66, x2=1460288943, rf=570a3daf
x=67, x2=1417339271, rf=547ae187
x=68, x2=1374389599, rf=51eb855f
x=69, x2=1331439927, rf=4f5c2937
x=70, x2=1288490255, rf=4ccccd0f
x=71, x2=1245540583, rf=4a3d70e7
x=72, x2=1202590911, rf=47ae14bf
x=73, x2=1159641239, rf=451eb897
x=74, x2=1116691567, rf=428f5c6f
x=75, x2=1073741895, rf=40000047
x=76, x2=1030792223, rf=3d70a41f
x=77, x2=987842551, rf=3ae147f7
x=78, x2=944892879, rf=3851ebcf
x=79, x2=901943207, rf=35c28fa7
x=80, x2=858993535, rf=3333337f
x=81, x2=816043863, rf=30a3d757
x=82, x2=773094191, rf=2e147b2f
x=83, x2=730144519, rf=2b851f07
x=84, x2=687194847, rf=28f5c2df
x=85, x2=644245175, rf=266666b7
x=86, x2=601295503, rf=23d70a8f
x=87, x2=558345831, rf=2147ae67
x=88, x2=515396159, rf=1eb8523f
x=89, x2=472446487, rf=1c28f617
x=90, x2=429496815, rf=199999ef
x=91, x2=386547143, rf=170a3dc7
x=92, x2=343597471, rf=147ae19f
x=93, x2=300647799, rf=11eb8577
x=94, x2=257698127, rf=f5c294f
x=95, x2=214748455, rf=ccccd27
x=96, x2=171798783, rf=a3d70ff
x=97, x2=128849111, rf=7ae14d7
x=98, x2=85899439, rf=51eb8af
x=99, x2=42949767, rf=28f5c87
x=100, x2=95, rf=5f
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签