64835

Draw multiple shapes in different views

Question:

I created a XML file containing two image view. I want to draw two different circles(different size, color) in the center of each view. How can I do that, especially the coordinates. Thanks!

Answer1:

you can do that using shape Drawables ...

create circle.xml in your Drawable Folder ...

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="@android:color/transparent"/> <corners android:radius="12px"/> <stroke android:width="2dp" android:color="#000000"/> </shape>

use it in your ImageView

<ImageView android:id="@+id/circleimage" android:layout_height="150dp" android:layout_width="150dp" android:src="@drawable/circle"> </ImageView>

You can use this circle.xml for one or more imageViews ...

Answer2:

Create a subclass of ImageView. Use that subclass in the XML. Then overwrite the

public void draw(Canvas canvas){ super.draw(canvas); // do your drawing here // canvas holds the drawable area // use canvas.drawXXXX methods with basic mathematics to put circles in places you need }

Hope this answers your question.

Recommend

  • how to use draggable and click separately in kineticjs?
  • How do I calculate radius of curvature from discrete samples?
  • Strange behavior from affine transform rotation on iOS
  • Java Paint if x = location do this else do this
  • Android Lock Screen C# .NET Replica
  • XSD with multi occurrences unordered
  • XOR with Neural Networks (Matlab)
  • How to resolve permission denied maybe missing internet permission?
  • Splash Screen will not display
  • Xamarin Android | Layout style
  • How to get current document uri in XSLT?
  • JBoss External Properties Files in Classpath
  • Access variable of ScriptContext using Nashorn JavaScript Engine (Java 8)
  • How Lists (specifically, RecyclerView with CardViews) in Android work
  • Code in Job's Script Block after Start-Process Does not Execute
  • Android - Material Design - NavigationView - How to put vertical scroll?
  • Why Encoding.ASCII != ASCIIEncoding.Default in C#?
  • Bad request using file_get_contents for PUT request in PHP
  • Jquery UI tool tip close icon
  • Paperclip, set path outside of rails root folder
  • When to use `image` and when to use `Matrix` in Emgu CV?
  • Pass value from viewmodel to script in zk
  • Encrypt data by using a public key in c# and decrypt data by using a private key in php
  • Uncaught Error: Could not find module `ember-load-initializers`
  • SSO with signing and signature validation doesn't work
  • Deserializing XML into class C#
  • How to include full .NET prerequisite for Wix Burn installer
  • Proper folder structure for lots of source files
  • Load html files in TinyMce
  • embed rChart in Markdown
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Append folder name and increment by 1 using batch script
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize