I am trying to draw a custom border by plotting a custom view. Here is a sample on one side of the border:
package com.sparkydev.guessprhrase; Import android.content.Context; Import Android.graphics. Canvas; Import android.graphics.color; Import android.graphics.drawable.ShapeDrawable; Import android.graphics.drawable.shapes.RectShape; Import android.util.AttributeSet; Import android.view.View; Expansion of the public class leftborder (see Private Sheepdrautable Variety, Horizonte; Public Left (Reference Reference, AttributeSet attributeset) {Super (Reference, Attributes); Int width = this.getWidth (); Int height = this.getHyight (); VertRect = New Size Drainage (New RectSpep); VertRect.getPaint () setColor (Color.RED); VertRect.setBounds (0, 0, width / 10, height); Horizontal = New shape framework (new RectSpep); HorizRect.getPaint () setColor (Color.RED); Horizontal .Setbound (0, 0, width, height / 9);} Safe Futile O Do not draw (canvas canvas) {vertRect.draw (canvas); horizRect.draw (canvas);}}
On the other hand, the definition is very similar. Defined:
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; RelativeLayout xmlns: android = "http: // schemas .android.com / apk / res / android "android: layout_width =" fill_parent "android: layout_height =" fill_parent "android: background =" @drawable / wallpaper "& gt; & Lt ;! - Excludes the status of the boundary, which is programmically drawn .-> And lieutenant; Com.sparkydev.guessprhrase.LeftBorderAndroid: ID = "@ + ID / LeftBorder" Android: Layout_Alternative Converter = "True" Android: Layout_Wind = "Fell_Parent" Android: Layout_Height = "Wrap-content" /> & Lt ;! - Used a frame layout to include the menu button. - & gt; & Lt; FrameLayout Android: id = "@ + id / frameLayout01" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" & gt; & Lt ;! - Menu button - & gt; & Lt; / FrameLayout & gt; & Lt ;! - Announces the position of the right border (on the right side of the screen, below the left border) - & gt; And lieutenant; Com.sparkydev.guessprhrase.RightBorderAndroid: Layout_LineParitroit = "True" Android: Layout_Width = "FillPart" Android: Layout_Height = "Wrap-content" Android: Layout_blow = "@Id / Left Border" /> & Lt; / RelativeLayout & gt;
The problem is that the boundaries are not visible at all. The background shows, but nothing else.
From
, when you create a custom view, it will be a set unless you specify otherwise 100x100 Let's see if there is anything with this issue that you are seeing.
"You definitely want to override the
. Measure ()
and it is also possible to override itonDraw ()
if You want to show something to the component, while the default behavior is the default, the defaultonDraw ()
will not do anything, and the defaultonMeasure ()
always has a size of 100x100 - which is probably not what you want. "
Comments
Post a Comment