Triangular shaped button for android activity

倖福魔咒の 提交于 2019-12-06 04:28:08

问题


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..


回答1:


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"/>



回答2:


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?



来源:https://stackoverflow.com/questions/25398788/triangular-shaped-button-for-android-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!