简体   繁体   English

android中的三角形状

[英]Triangle shape in android

I have referred many StackOverflow questions regarding drawing triangle shapes. 我已经提到了很多关于绘制三角形形状的StackOverflow问题。

But, I have a special case here. 但是,我在这里有一个特例。 Following is a combined shape I want to create. 以下是我想要创建的组合形状。 Rectangle, I can manage. 矩形,我可以管理。 But, I am facing issues with the triangle. 但是,我正面临着三角形的问题。 I am getting confused with the angles. 我对角度感到困惑。

Angles of the triangle are mentioned. 提到三角形的角度。

I have the following code, already : 我已经有以下代码:

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item >
        <rotate
            android:fromDegrees="-45"
            android:toDegrees="0"
            android:pivotX="270%"
            android:pivotY="180%" >

            <shape
                android:shape="rectangle"  >
                <stroke android:color="@android:color/transparent" android:width="10dp"/>
                <solid
                    android:color="#000000"  />
            </shape>
        </rotate>
    </item>
</layer-list>

在此输入图像描述

I want to know the following values that satisfies my need : 我想知道满足我需求的以下值:

android:fromDegrees=?
android:toDegrees=?
android:pivotX=?
android:pivotY=?

Please, help me with this. 请在这件事上给予我帮助。

Since I am guessing the point you have stuck has nothing to do with android (meaning you know how to create a random triangle) you need help to find the 3 points. 由于我猜测你卡住的点与android无关(意思是你知道如何创建随机三角形),你需要帮助才能找到3分。 Assuming you know the point in the 50 degrees ( x1,y1 ), 假设你知道50度( x1,y1 )的点,

  1. The point in the 90 has coords ( x1+d1,y1 ) where d1 is distance of the edge connecting those 2 points. 90中的点具有坐标( x1+d1,y1 ),其中d1是连接这2个点的边缘的距离。
  2. The point in the bottom has coords ( x1+d1,y2 ), where y2 = acos(50)*d1 . 底部的点具有坐标( x1+d1,y2 ),其中y2 = acos(50)*d1 Of course atan2 should take degrees to work or you must convert it to rads. 当然atan2应该使用度数来工作,或者你必须将它转换为rads。

This is the general idea. 这是一般的想法。 If it happens to know another point you act in the same way. 如果碰巧知道另一点你以同样的方式行事。 Hope that helped. 希望有所帮助。

i can draw triangle shape using XML how you can use as per your requirement that i don't know 我可以使用XML绘制三角形,如何根据您的要求使用我不知道的

triangle .xml

<item>
    <rotate
        android:fromDegrees="45"
        android:pivotX="-40%"
        android:pivotY="87%"
        android:toDegrees="45" >
        <shape android:shape="rectangle" >
            <stroke
                android:width="10dp"
                android:color="#00000000" />

            <solid android:color="#00ACED" />  //your color
        </shape>
    </rotate>
</item>

三角形

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM