Transparent Panel extends LinearLayout : LinearLayout « UI « Android






Transparent Panel extends LinearLayout

   
//package com.reverb;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.LinearLayout;

public class TransparentPanel extends LinearLayout {
  
  //Fields
  private Paint innerPaint, borderPaint;
  
  public TransparentPanel(Context context) {
    super(context);

    init();
  }

  public TransparentPanel(Context context, AttributeSet attrs) {
    super(context, attrs);

    init();
  }
  
  private void init()  {
    innerPaint = new Paint();
    innerPaint.setARGB(120, 170, 170, 170); // gray
    innerPaint.setAntiAlias(true);

    borderPaint = new Paint();
    borderPaint.setARGB(230, 240, 240, 240);
    borderPaint.setAntiAlias(true);
    borderPaint.setStyle(Style.STROKE);
    borderPaint.setStrokeWidth(2);
  }
  
  @Override
  protected void dispatchDraw(Canvas canvas) {

    RectF drawRect = new RectF();
    drawRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());

    canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
    canvas.drawRoundRect(drawRect, 5, 5, borderPaint);

    super.dispatchDraw(canvas);
  }

}

   
    
    
  








Related examples in the same category

1.Adding two controls to LinearLayout
2.Using LinearLayout for Activity
3.Using LinearLayout to layout two RadioGroups
4.Using LinearLayout.LayoutParams
5.LinearLayout for ListAdapter
6.Using LinearLayout
7.LinearLayout which uses a combination of wrap_content on itself and match_parent on its children to get every item to be the same width.
8.LinearLayout inside ScrollView
9.Set min height
10.Set padding right
11.Set padding with dpi value
12.Baseline alignment includes a android.widget.LinearLayout within another android.widget.LinearLayout.