Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a line in diagonal direction on a widget android

Tags:

android

I want to know is there a simple way to draw a line in diagonal direction, like using <View .... /View> in xml to draw line in vertical or horizontal direction.

Below is the image of what I want to do

Selected form of button
enter image description here

Unselected form of button
enter image description here

Changing color of text is not a problem, its drawing line for unselected case and making invisible for selected one. Thank you

like image 650
shehzy Avatar asked Apr 28 '17 07:04

shehzy


1 Answers

Create a transparent image with diagonal line and add that image as an overlay.

or create an shape xml of diagonal and add in your drawable. below is code to create diagonal shape.

  <?xml version="1.0" encoding="utf-8"?>
  <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
  <rotate
   android:fromDegrees="160"
   android:pivotX="50%"
   android:pivotY="50%"
   android:toDegrees="0">
   <shape
    android:shape="line"
    android:top="1dip">
    <stroke
       android:width="3dp"
       android:color="#FF0000"/>
         </shape>
         </rotate>
         </item>
         </layer-list>
like image 113
anddevmanu Avatar answered Nov 11 '22 05:11

anddevmanu