title: Android: how to draw a border to a LinearLayout
body: <p>I have three files. The XML, the draw function and the main Activity.
  I have some <code>LinearLayout</code> in my XML file.</p>
  <pre><code>&lt;LinearLayout android:orientation=&quot;horizontal&quot;
                android:layout_width=&quot;fill_parent&quot;
                android:layout_height=&quot;fill_parent&quot;
                android:layout_weight=&quot;1&quot;&gt;
      &lt;LinearLayout android:layout_width=&quot;fill_parent&quot;
                    android:layout_height=&quot;fill_parent&quot;
                    android:layout_weight=&quot;1&quot;
                    android:background=&quot;#ef3&quot;
                    android:id=&quot;@+id/img01&quot;/&gt;
      &lt;LinearLayout android:layout_width=&quot;fill_parent&quot;
                    android:layout_height=&quot;fill_parent&quot;
                    android:layout_weight=&quot;1&quot;
                    android:background=&quot;#E8A2B4&quot;
                    android:id=&quot;@+id/img02&quot;/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  <p>This is the draw function:</p>
  <pre><code>public class getBorder extends TextView {
      public getBorder(Context context) {
          super(context);
      }
  
      @Override
      protected void onDraw(Canvas canvas) {
          super.onDraw(canvas);
          Paint paint = new Paint();
  
          paint.setColor(android.graphics.Color.RED);
  
          canvas.drawLine(0, 0, this.getWidth() - 1, 0, paint);
          canvas.drawLine(0, 0, 0, this.getHeight() - 1, 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);
      }
  }
  </code></pre>
  <p>And this is the main Activity:</p>
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      final getBorder getBorder = new getBorder(this);
      final LinearLayout img01 = (LinearLayout) findViewById(R.id.img01);
      img01.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              getBorder.setWidth(100);
              getBorder.setHeight(100);
              img01.addView(getBorder);
          }
      });       
  }
  </code></pre>
  <p>The program could draw border but the size doesn't fit the <code>LinearLayout</code>. And when I click the <code>LinearLayout</code> again, the program crashed.</p>
  <p>Also, I want to draw two circles in the center of the <code>LinearLayout</code>, but how could I figure out the center coordinates?</p>