ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • shadow샘플
    과거...../개발일지 2010. 10. 6. 08:45
    bitmap파일로 구현한 shadow샘플 예제 입니다.

    TestView.java

     public class TestView extends View {

     private Context mContext;
     Bitmap sampleBitmap, sampleLine;
     int mWidth;
     int mHeight;
     ImageView imageView;
     
     public TestView(Context context) {
      super(context);  
      this.mContext = context;
      
      setWillNotDraw(false);
      
      sampleBitmap = BitmapFactory.decodeResource( this.getResources(),
         R.drawable.test);
      sampleLine = BitmapFactory.decodeResource( this.getResources(),
         R.drawable.testline);
      mWidth = sampleBitmap.getWidth();
      mHeight = sampleBitmap.getHeight();
      
     }
     
     
     
     @Override
     protected void onDraw(Canvas canvas) {
      
      
      drawBlackRect(canvas,sampleBitmap.getWidth(),sampleBitmap.getHeight(),10);
      
      Paint p = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG);
      
      //p.setShadowLayer(3,0,0,0xffffffff);
      p.setShadowLayer(10,0,0,android.graphics.Color.BLACK);
      p.setColor(android.graphics.Color.BLACK);
      canvas.drawBitmap(sampleBitmap, 10.0f,10.0f,null);  
      //canvas.drawBitmap(sampleLine, 5.0f,5.0f, null);
      
      
      DrawLayoutLine(canvas);
      super.onDraw(canvas);
     }
     
     
     private void drawBlackRect(Canvas canvas,int width, int height, int startDraw){
      Paint aa = new Paint();
      //aa.setShadowLayer(5,0,0,android.graphics.Color.BLACK);
      
        
      
      int distance =29;
      
      Rect endR = new Rect();
      endR.left = startDraw-distance;
      endR.right = startDraw+ width+distance+1;
      endR.top = startDraw-distance;
      endR.bottom = startDraw + height+distance-2;
      
      
      canvas.drawBitmap(sampleLine, null, endR, aa);
       
     }
     
     
     private void DrawLayoutLine(Canvas canvas){

      setWillNotDraw(false); 
      DashPathEffect dashPath = new DashPathEffect(new float[]{8,3}, 1); 
      
      Paint paint = new Paint();
            paint.setColor(android.graphics.Color.BLACK);
            //paint.setShadowLayer(5f,2f, 10f, 8);       
            //paint.setShader(shader)
            paint.setPathEffect(dashPath);
            paint.setStrokeWidth(1);

      
      canvas.drawLine(0, 0, this.getWidth() - 1, 0, paint);
      canvas.drawLine(0, 0, 0, this.getHeight() - 10, paint);
      canvas.drawLine(this.getWidth() - 1, 0, this.getWidth() - 1, this
        .getHeight() - 1, paint);
      canvas.drawLine(0, this.getHeight() - 1, this.getWidth() - 1, this
        .getHeight() - 1, paint);
      
     }
     
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
        
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
      Log.i("viewImage measure","viewImae measure");
      if(mWidth!=0 && mHeight !=0){
       int width = MeasureSpec.getSize(mWidth + 40);
       int height = MeasureSpec.getSize(mHeight + 40);
       setMeasuredDimension(width, height);
       Log.i("size Control","size Control");
      }
     }
     
     

    }


    ShadowSample.java
     public class ShadowSample extends Activity {
        /** Called when the activity is first created. */
     
     
     LinearLayout layout;
     LayoutParams layoutParams;
     
     
     @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
           
            
            layout = (LinearLayout)findViewById(R.id.layout);
            layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
        LayoutParams.WRAP_CONTENT);
            TestView viewTest = new TestView(this);
            layout.addView(viewTest);
           
           
        }
       
       
    }




Designed by Tistory.