如何以编程方式为android中透明视图的每个边框指定不同的颜色?

如何以编程方式为android中透明视图的每个边框指定不同的颜色?,android,xamarin,android-recyclerview,Android,Xamarin,Android Recyclerview,我有一个recyclerview,它的项目有多个模板。我的recyclerview是透明的,它的所有模板都在下面的代码中给出 <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="m

我有一个recyclerview,它的项目有多个模板。我的recyclerview是透明的,它的所有模板都在下面的代码中给出

 <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"     
    android:background="@android:color/white"            
    android:alpha="0.25">   
</LinearLayout>   
  <MvvmCross.Droid.Support.V7.RecyclerView.MvxRecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"            
        android:paddingLeft="10dp"        
        android:paddingTop="15dp"
        android:background="@android:color/transparent"
        android:scrollbarSize="20dp"            android:scrollbarStyle="outsideInset"MvxTemplateSelector="RMH.POS.Mobile.Android.ProductListTemplateSelector,RMH.POS.Mobile.Android"
        android:id="@+id/mvxRV" />
</FrameLayout>
使用上述方法,我无法实现视图的透明背景

该项目正在使用Xamarin的Android原生应用程序进行开发

public class DividerItemDecorator : ItemDecoration
{
    private static View firstView, secondView, thirdView;
    public DividerItemDecorator()
    {
    }

    protected DividerItemDecorator(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
    {
    }

    public override void OnDraw(Canvas c, RecyclerView parent, State state)
    {
        base.OnDraw(c, parent, state);
    }

    public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, State state)
    {
        base.GetItemOffsets(outRect, view, parent, state);
        //await Task.Factory.StartNew(() => { });
        if (parent.GetLayoutManager() is GridLayoutManager)
        {
            GridLayoutManager grid;
            int spanSize = 0;
            grid = parent.GetLayoutManager() as GridLayoutManager;
            spanSize = grid.GetSpanSizeLookup().GetSpanSize(parent.GetChildAdapterPosition(view));
            GridLayoutManager.LayoutParams layoutParams = (GridLayoutManager.LayoutParams)view.LayoutParameters;
            float c = layoutParams.SpanIndex;
            if (spanSize != 3)
            {
                if (c == 0)
                {
                    LayerDrawable bottomBorder = getBorders(
                        "#bba79e", // Background color
                        "#ad9f9c", // Border color
                        0, // Left border in pixels
                        0, // Top border in pixels
                        2, // Right border in pixels
                        2 // Bottom border in pixels
                    );
                    view.Background = bottomBorder;
                    firstView = view;
                    secondView = null;
                    thirdView = null;
                }
                if (c == 1)
                {
                    LayerDrawable bottomBorder = getBorders(
                        "#bba79e", // Background color
                        "#ad9f9c", // Border color
                        0, // Left border in pixels
                        0, // Top border in pixels
                        2, // Right border in pixels
                        2 // Bottom border in pixels
                    );
                    view.Background = bottomBorder;
                    secondView = view;
                    thirdView = null;
                }
                if (c == 2)
                {
                    LayerDrawable bottomBorder = getBorders(
                        "#bba79e", // Background color
                        "#ad9f9c", // Border color
                        0, // Left border in pixels
                        0, // Top border in pixels
                        0, // Right border in pixels
                        2 // Bottom border in pixels
                    );
                    view.Background = bottomBorder;
                    thirdView = view;
                }
            }
            else
            {
                if (firstView != null)
                {
                    LayerDrawable bottomBorder = getBorders(
                        "#bba79e", // Background color
                        "#ad9f9c", // Border color
                        0, // Left border in pixels
                        0, // Top border in pixels
                        2, // Right border in pixels
                        0 // Bottom border in pixels
                    );
                    firstView.Background = bottomBorder;
                }
                if (secondView != null)
                {
                    LayerDrawable bottomBorder = getBorders(
                       "#bba79e", // Background color
                       "#ad9f9c", // Border color
                       0, // Left border in pixels
                       0, // Top border in pixels
                       2, // Right border in pixels
                       0 // Bottom border in pixels
                   );
                    secondView.Background = bottomBorder;
                }
                if (thirdView != null)
                {
                    LayerDrawable bottomBorder = getBorders(
                       "#bba79e", // Background color
                       "#ad9f9c", // Border color
                       0, // Left border in pixels
                       0, // Top border in pixels
                       0, // Right border in pixels
                       0 // Bottom border in pixels
                   );
                    thirdView.Background = bottomBorder;
                }
                LayerDrawable bottomBorderHeader = getBorders(
                       "#bba79e", // Background color
                       "#ad9f9c", // Border color
                       0, // Left border in pixels
                       2, // Top border in pixels
                       0, // Right border in pixels
                       2 // Bottom border in pixels
                   );

                view.Background = bottomBorderHeader;
            }
        }
        else
        {
            LinearLayoutManager llm;
            llm = parent.GetLayoutManager() as LinearLayoutManager;
            if (!(view is RelativeLayout))
            {
                LayerDrawable bottomBorder = getBorders(
                           "#bba79e", // Background color
                           "#ad9f9c", // Border color
                           0, // Left border in pixels
                           1, // Top border in pixels
                           0, // Right border in pixels
                           1 // Bottom border in pixels
                       );
                view.Background = bottomBorder;
            }
            else
            {
                LayerDrawable bottomBorder = getBorders(
                          "#bba79e", // Background color
                          "#ad9f9c", // Border color
                          0, // Left border in pixels
                          0, // Top border in pixels
                          0, // Right border in pixels
                          0 // Bottom border in pixels
                      );
                view.Background = bottomBorder;
            }
        }
    }
    public override void OnDrawOver(Canvas c, RecyclerView parent, State state)
    {
        base.OnDrawOver(c, parent, state);
    }
    // Custom method to generate one or multi side border for a view
    protected LayerDrawable getBorders(string bgColor, string borderColor,
                                  int left, int top, int right, int bottom)
    {
        // Initialize new color drawables
        ColorDrawable borderColorDrawable = new ColorDrawable(Color.ParseColor(borderColor));
        ColorDrawable backgroundColorDrawable = new ColorDrawable(Color.Transparent);

        // Initialize a new array of drawable objects
        Drawable[] drawables = new Drawable[]{
            borderColorDrawable
        };

        // Initialize a new layer drawable instance from drawables array
        LayerDrawable layerDrawable = new LayerDrawable(drawables);

        //layerDrawable.SetAlpha(0);
        // Set padding for background color layer
        layerDrawable.SetLayerInset(
                0, // Index of the drawable to adjust [background color layer]
                left, // Number of pixels to add to the left bound [left border]
                top, // Number of pixels to add to the top bound [top border]
                right, // Number of pixels to add to the right bound [right border]
                bottom // Number of pixels to add to the bottom bound [bottom border]
        );
        // Finally, return the one or more sided bordered background drawable
        return layerDrawable;
    }
}