I'm trying to make a dotted line. I'm using this right now for a solid line:
LinearLayout divider = new LinearLayout( this );
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, 2 );
divider.setLayoutParams( params );
divider.setBackgroundColor( getResources().getColor( R.color.grey ) );
I need something like this, but dotted instead of solid. I'd like to avoid making hundreds of layouts alternating between a transparent layout and solid layout.
The only thing that worked for me and I think it is the simplest way is using a Path with a paint object like this:
Then onDraw(): (important call reset if you change those points between ondraw calls, cause Path save all the movements)
the path effect is set on the paint object
you can create all sorts of dotted patterns by supplying more numbers in the int[] array it specifies the ratios of dash and gap. This is a simple, equally dashed, line.
Create xml (view_line_dotted.xml):
Set as background of your view:
Best Solution for Dotted Background working perfect
I have created dashed dotted line for EditText. Here you go. Create your new xml. e.g dashed_border.xml Code here:
And use your new xml file in your EditText for example:
Cheers! :)
Without java code:
drawable/dotted.xml:
view.xml: