Triangular shaped button for android activity

2019-04-09 20:53发布

In my android application activity, I need to arrange 6 buttons as shown below: The buttons are named from 1 to 6. When I try to add each button as background to the buttons, there is a problem that the buttons are overlapping each other. The background png image of the button are triangular in shape. When I add these background png to the buttons, its background image changes, but the borders of the button are still rectangle in shape. So I need the buttons with triangular borders, so that I can place them in a format like the below screenshot. Also I don't which layout suits most for this type pattern. So please do suggest that also..

enter image description here

2条回答
Anthone
2楼-- · 2019-04-09 20:58

Try this for triangle shape: call it as a background for your textview or any.

triangle.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item>
      <rotate
        android:fromDegrees="45"
        android:toDegrees="45"
        android:pivotX="-40%"
        android:pivotY="100%"
        >
           <shape android:shape="rectangle">

              <corners android:radius="15dip" />
              <solid android:color="@color/blue" />
           </shape>
      </rotate>
   </item>
</layer-list>

//TEXTVIEW CALLING

<TextView
  android:layout_width="@dimen/triangle"
  android:layout_height="@dimen/triangle"
  android:rotation="90"
  android:layout_centerVertical="true"
  android:background="@drawable/triangle"/>
查看更多
欢心
3楼-- · 2019-04-09 21:12

Check this answer of mine, i think you can follow this approach to achieve your goal.. [How to make ImageButtons bounds wrap around the image?

查看更多
登录 后发表回答