如何在android中制作水平配色方案

时间:2017-03-11 12:14:38

标签: android listview colors color-scheme

我正在使用谷歌视觉API,它可以返回如下图片的配色方案:

exception breakpoint

API本身返回值以计算RGB值的确切颜色,并计算图像中包含该颜色的图像的百分比。

我正在尝试创建第一张图片中的内容。但我不知道如何做到这一点,到目前为止我只有一个列表视图,给出了这里的概述。

google vision color scheme

有没有人知道如何在Android中创建一个水平配色方案,我自己指定所有颜色?即使水平列表视图也可以使用每种颜色的动态宽度来反映百分比。

谢谢!

2 个答案:

答案 0 :(得分:1)

您可以使用LinearLayout并以幻想方式添加子视图,weight等于颜色的百分比:

// sample colors
final int color1 = Color.parseColor("#8da921");
final int color2 = Color.parseColor("#1f0929");
final int color3 = Color.parseColor("#f0b991");

// sample color percentages
final int colorPercentage1 = 60;
final int colorPercentage2= 10;
final int colorPercentage3 = 30;

// you should have this layout defined in your xml
final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
linearLayout.setWeightSum(100);

// create the views
final View view1 = new View(this);
final LinearLayout.LayoutParams viewParams1 = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT);
viewParams1.weight = colorPercentage1;
view1.setLayoutParams(viewParams1);
view1.setBackgroundColor(color1);

final View view2 = new View(this);
final LinearLayout.LayoutParams viewParams2 = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT);
viewParams2.weight = colorPercentage2;  
view2.setLayoutParams(viewParams2);
view2.setBackgroundColor(color2);

final View view3 = new View(this);
final LinearLayout.LayoutParams viewParams3 = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT);
viewParams3.weight = colorPercentage3;         
view3.setLayoutParams(viewParams3);
view3.setBackgroundColor(color3);

//finally add the views
linearLayout.addView(view1);
linearLayout.addView(view2);
linearLayout.addView(view3);

答案 1 :(得分:0)

  

如何在android中制作水平配色方案

只需在具有水平方向的LinearLayout内使用不同权重的视图进行充气。