-1

I need to draw this type of view (in the red circle) in the android app. Please let me know how I can achieve it.

enter image description here

satish123
  • 507
  • 7
  • 24
  • Hi - could you post some code that you have already written by yourself? This can be done in many ways (custom views, drawables, even by including a graphic) – scana Dec 29 '15 at 19:56

1 Answers1

1

today was solved pretty similar problem. Please check my answer here:

How to make custom textview in android?

If you still have any question please free to ask

EDIT: Here's some customization of my answer:

enter image description here

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tool="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/colorPrimary">

    <RelativeLayout
        android:id="@+id/item"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="#FFFFFFFF">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="40dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_margin="0dp"
            android:src="@drawable/laptop"/> 

        <ImageView
            android:layout_width="175dp"
            android:layout_height="175dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_margin="0dp"
            android:padding="0dp"
            android:src="@drawable/triangle"/> //here's your triangle

        <ImageView
            android:layout_width="175dp"
            android:layout_height="175dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_margin="0dp"
            android:padding="0dp"
            android:rotation="90.0"
            android:src="@drawable/triangle"/> //here's your triangle

        <ImageView
            android:layout_width="175dp"
            android:layout_height="175dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_margin="0dp"
            android:padding="0dp"
            android:rotation="180.0"
            android:src="@drawable/triangle"/> //here's your triangle

        <ImageView
            android:layout_width="175dp"
            android:layout_height="175dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_margin="0dp"
            android:padding="0dp"
            android:rotation="270.0"            
            android:src="@drawable/triangle"/> //here's your triangle

    </RelativeLayout>

</RelativeLayout>

I also give some notes about triangle.xml which you need to put to drawable folder:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <rotate
            android:fromDegrees="-45"             
            android:toDegrees="0"
            android:pivotX="150%"
            android:pivotY="20%" >
            <shape
                android:shape="rectangle" > // transform from rectangle
                <solid android:color="#ff0000" />   //color of triangle
            </shape>
        </rotate>
    </item>
</layer-list>

If you need to change color of this right-angled triangle change this lines:

      <solid android:color="#ff0000" />  

If you need to more triangles with many colors... sorry, but you would need to create some more xml files

If you need to change a size of triangle, change these lines:

            android:layout_width="175dp"
            android:layout_height="175dp"

NOTE: I know that this solution is not the best one, but I can advice you to look for triangle drawable, triangled button (maybe on GitHub you would find).

Star icon you would find in Material Design library. Just add to your build.gradle this line:

      compile 'com.android.support:design:23.x'

Hope it help

Community
  • 1
  • 1
piotrek1543
  • 18,676
  • 7
  • 78
  • 92
  • Hi, Your solution looks good to me. Just as am new to tag, can you tell me if I need to draw a right-angled triangle on the top-left side, what will android:fromDegrees, android:toDegrees, android:pivotX, android:pivotY values be? – satish123 Dec 29 '15 at 20:02
  • Well, I don't think you need them to use them :-D Just set size of `ImageView`, where the `triangle` is as `src` and rotate it by set `android:rotation`. I think that would be enough – piotrek1543 Dec 29 '15 at 20:12
  • Hi piotrek, unfortunately, it's not working this way – satish123 Dec 29 '15 at 20:26
  • tell me what is not working or add to your post drawing of your layout. – piotrek1543 Dec 29 '15 at 23:03