Reputation: 21937
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
?
Could anyone guide me how to draw a shape like this.
Upvotes: 0
Views: 207
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
Upvotes: 2
Reputation: 855
You can rotate the view by some degree. That should solve your problem, shouldn't it?
Upvotes: 0
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