use a Transparent.java as a xml declaration ??

Put your problem here if it does not fit any of the other categories.

use a Transparent.java as a xml declaration ??

Postby tsdt » Mon Mar 24, 2008 12:09 pm

I wrote a Transparent.java and use it to define like a view class in xml:
code java:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class TransparentPanel extends LinearLayout{
  3.  
  4.         private Paint innerPaint, borderPaint;
  5.  
  6.         public TransparentPanel(Context myContext){
  7.  
  8.                 super(myContext);
  9.  
  10.                 this.setOrientation(LinearLayout.HORIZONTAL);
  11.  
  12.                 init();
  13.  
  14.         }
  15.  
  16.         private void init() {
  17.  
  18.                 innerPaint = new Paint();
  19.  
  20.                 innerPaint.setARGB(225, 75, 75, 75); //gray
  21.  
  22.                 innerPaint.setAntiAlias(true);
  23.  
  24.                 borderPaint = new Paint();
  25.  
  26.                 borderPaint.setARGB(255, 255, 255, 255);
  27.  
  28.                 borderPaint.setAntiAlias(true);
  29.  
  30.                 borderPaint.setStyle(Style.STROKE);
  31.  
  32.                 borderPaint.setStrokeWidth(2);
  33.  
  34.         }
  35.  
  36.         public void setInnerPaint(Paint innerPaint) {
  37.  
  38.                 this.innerPaint = innerPaint;
  39.  
  40.         }
  41.  
  42.         public void setBorderPaint(Paint borderPaint) {
  43.  
  44.                 this.borderPaint = borderPaint;
  45.  
  46.         }
  47.  
  48.         public TransparentPanel(Context context, AttributeSet attrs,Map inflateParams) {
  49.  
  50.                 super(context, attrs, inflateParams);
  51.  
  52.                 init();
  53.  
  54.         }
  55.  
  56.         protected void dispatchDraw(Canvas canvas) {
  57.  
  58.         RectF drawRect = new RectF();
  59.  
  60.         drawRect.set(0,0, getMeasuredWidth(), getMeasuredHeight());
  61.  
  62.         canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
  63.  
  64.         canvas.drawRoundRect(drawRect, 5, 5, borderPaint);
  65.  
  66.     }
  67.  
  68. }
  69.  
  70.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


define in XML:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.    android:orientation="vertical"
  7.  
  8.    android:id="@+id/total"
  9.  
  10.    android:layout_width="fill_parent"
  11.  
  12.    android:layout_height="fill_parent"
  13.  
  14.    >
  15.  
  16.         <android.asnet.ttttttt.TransparentPanel
  17.  
  18.        android:id="@+id/transparent_panel"
  19.  
  20.        android:layout_width="fill_parent"
  21.  
  22.        android:layout_height="wrap_content"
  23.  
  24.        android:paddingLeft="5px"
  25.  
  26.        android:paddingTop="5px"
  27.  
  28.        android:paddingRight="5px"
  29.  
  30.        android:paddingBottom="5px">
  31.  
  32.  
  33.  
  34.                 <Button android:id="@+id/button_click_me"
  35.  
  36.                 android:layout_width="wrap_content"
  37.  
  38.                 android:layout_height="wrap_content"
  39.  
  40.                 android:text="Click Me!"/>
  41.  
  42.  
  43.  
  44.       </android.asnet.ttttttt.TransparentPanel>
  45.  
  46. </LinearLayout>
  47.  
  48.  
  49.  
  50.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


Main java file just use: setContentView(R.layout.main);
My main purpose: use the Transparent Panel.java like a declaration in xml (in XML, this TransparentPanel contain a Button ).But the trouble i met is the Button do not display ,the screen only show the transparent rectangle
TSDT
tsdt
Junior Developer
Junior Developer
 
Posts: 12
Joined: Wed Jan 09, 2008 4:20 am
Location: VIETNAM

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests