Draw circle from main Activity or change view

Jemil Riahi

I am a real newbie when it comes to android programming. I am trying to figure out how to change view on the fly or draw circles from the main activity.

I have tried to change view but i failed. So now i am trying to figure out how i should paint a circle from my main activity after the client clicks on a button

private void InitiateGame(String name, String password){
    Log.d("InitiatingGame", "Initiating Game");
    NetworkHandler networkHandler = new NetworkHandler(HOST, PORT);
    PlayerHandler playerHandler = new PlayerHandler();
    MessageHandler messageHandler = new MessageHandler(networkHandler, playerHandler);

    networkHandler.connect(name, password);
    final GameHandler zombieView = new GameHandler(networkHandler, messageHandler, playerHandler);  
    nameField.post(new Runnable() 
    {
        @Override
        public void run() 
        {
            setMainScreenVisibility(View.INVISIBLE);
        }
    });
    initiated = true;
}

This is the code that is called after the client have clicked on the "Connect" Button. So he will instanciate some classes that you guys dont need to know what they are doing. Then he connects to the server. So i do not want to make new intent's.

What is better. Create a new view class that extends view that i set as contentview?(if so. how?) Or should i just try to draw these circles from this main activity? (also how?)

Libin

To draw a circle using paint , you need to create a custom view like this

 private class CircleView extends View{
    Paint paint = new Paint();

    public CircleView(Context context) {
        super(context);
    }

    @Override
    public void onDraw(Canvas canvas) {
        paint.setColor(Color.GREEN);
        // set your own position and radius
        canvas.drawCircle(100,200,100,paint);
    }
}

And, then add an Parent Layout to the Activity

RelativeLayout relativeLayout = new RelativeLayout(this);
    relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(
        ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

 setContentView(relativeLayout);

Finally you need to add the circle view to the Parent Layout

 relativeLayout.addView(new CircleView(this));

Another way is to create the circle as drawable xml and set it to an ImageView

Create a circle.xml in drawable/

And then , set the drawable in ImageView in your layout

 <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/circle"/>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to change data of Main Activity from Fragment

From Dev

How to draw a circle in an Android native application activity

From Dev

Draw circle without having to switch activity?

From Dev

Call a function defined in a fragment, from the main activity that required a view

From Dev

How to correctly retrieve view from fragment in main activity

From Dev

Draw circle from using points

From Dev

App icon not being created when i change the launcher activity from LoginActivity to Main2Activity

From Dev

How to use a custom class (which extends View class) in activity class to draw path without changing the other parts of the main layout in android

From Dev

Calling custom view from main activity.. Message in onDraw() is printed but custom view is not rendered

From Dev

Calling custom view from main activity.. Message in onDraw() is printed but custom view is not rendered

From Java

Draw a perfect circle from user's touch

From Dev

By the "Settings Activity" go and change the main activity to another activity

From Dev

removing a view from the activity

From Dev

jump from main activity to last visited activity

From Dev

How to back to Main activity from the notification activity?

From Dev

Bundle from main activity to fragment

From Dev

i need to get the context from my main Activity inside my view class

From Dev

Put a ListActivity "in" my main activity view

From Dev

row layout not set on on Main Activity Recycler View

From Dev

Change to Activity from Fragment

From Dev

Change Activity from menu

From Dev

Change to Activity from Fragment

From Dev

Change from Activity to AppCompatActivity

From Dev

How to change showcase view circle size in android

From Dev

Draw circle when touched and when touch is removed in a custom view

From Dev

Draw Circle in the background of Text View, over each image in Fragment

From Dev

How to draw a Field of View of Camera using Circle in WPF?

From Dev

How to make a DialogFragment change text in activity main?

From Dev

How to change MAIN activity during runtime

Related Related

  1. 1

    How to change data of Main Activity from Fragment

  2. 2

    How to draw a circle in an Android native application activity

  3. 3

    Draw circle without having to switch activity?

  4. 4

    Call a function defined in a fragment, from the main activity that required a view

  5. 5

    How to correctly retrieve view from fragment in main activity

  6. 6

    Draw circle from using points

  7. 7

    App icon not being created when i change the launcher activity from LoginActivity to Main2Activity

  8. 8

    How to use a custom class (which extends View class) in activity class to draw path without changing the other parts of the main layout in android

  9. 9

    Calling custom view from main activity.. Message in onDraw() is printed but custom view is not rendered

  10. 10

    Calling custom view from main activity.. Message in onDraw() is printed but custom view is not rendered

  11. 11

    Draw a perfect circle from user's touch

  12. 12

    By the "Settings Activity" go and change the main activity to another activity

  13. 13

    removing a view from the activity

  14. 14

    jump from main activity to last visited activity

  15. 15

    How to back to Main activity from the notification activity?

  16. 16

    Bundle from main activity to fragment

  17. 17

    i need to get the context from my main Activity inside my view class

  18. 18

    Put a ListActivity "in" my main activity view

  19. 19

    row layout not set on on Main Activity Recycler View

  20. 20

    Change to Activity from Fragment

  21. 21

    Change Activity from menu

  22. 22

    Change to Activity from Fragment

  23. 23

    Change from Activity to AppCompatActivity

  24. 24

    How to change showcase view circle size in android

  25. 25

    Draw circle when touched and when touch is removed in a custom view

  26. 26

    Draw Circle in the background of Text View, over each image in Fragment

  27. 27

    How to draw a Field of View of Camera using Circle in WPF?

  28. 28

    How to make a DialogFragment change text in activity main?

  29. 29

    How to change MAIN activity during runtime

HotTag

Archive