androidcodehunter
androidcodehunter

Reputation: 21937

How to draw shape like this one in android?

I am trying to draw shape like this picture below in android. I want to place this view on a RelativeLayout. And I will set onClickListener for this View. Is it possible to draw a View like this and set onClickListener?

enter image description here

Could anyone guide me how to draw a shape like this.

Upvotes: 0

Views: 207

Answers (3)

rperryng
rperryng

Reputation: 3253

If you are targetting api level 11 and up, there is a method already included for rotating views

in the xml, call android:rotation="45", or if wanted programmatically, get a reference to the view and call someView.setRotation(45)

final LinearLayout textContainer = (LinearLayout) findViewById(R.id.yourLinearLayoutId);
textContainer.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View arg0) {
        textContainer.setRotation(getRotation() + 45);
    }
});

Really though, this works try it out

Upvotes: 2

StarDust
StarDust

Reputation: 855

You can rotate the view by some degree. That should solve your problem, shouldn't it?

Upvotes: 0

Niko
Niko

Reputation: 8153

Implement a custom View, override onDraw method. There you rotate the Canvas and draw rectangle and text.

You also need to override onMeasure to get proper size for the view.

Upvotes: 0

Related Questions