2017-07-04 12 views
0

私はXML layoutに三角形を描こうとしています。三角形のドロアブルを作成するには?

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <rotate 
      android:fromDegrees="45" 
      android:pivotX="135%" 
      android:pivotY="1%" 
      android:toDegrees="45"> 
      <shape android:shape="rectangle"> 
       <solid android:color="@color/red" /> 
      </shape> 
     </rotate> 
    </item> 
</layer-list> 

enter image description here

私の期待は私のdrawable以下のような画像の右上を構築することです。 私はこのdrawableをリスト項目に追加する必要があります。あなたはこれを試すことができ

enter image description here

+0

これはお使いになりましたか? https://looksok.wordpress.com/2013/08/24/android-triangle-arrow-defined-as-an-xml-shape/ – Dziugas

答えて

1

enter image description here描画可能backround_triangle.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <rotate 
      android:fromDegrees="45" 
      android:toDegrees="45" 
      android:pivotX="250%" 
      android:pivotY="80%"> 
      <shape android:shape="rectangle"> 
       <solid android:color="@color/colorAccent" /> 
      </shape> 
     </rotate> 
    </item> 
</layer-list> 

次のように表示されます。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:cardCornerRadius="4dp" 
    app:cardPreventCornerOverlap="false" 
    app:cardUseCompatPadding="false"> 


    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/background_triangle"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:padding="@dimen/dp8" 
      android:weightSum="1"> 

      <LinearLayout 
       android:id="@+id/img_view" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_centerVertical="true" 
       android:gravity="center" 
       android:orientation="vertical"> 

       <de.hdodenhof.circleimageview.CircleImageView 
        android:id="@+id/contact_img" 
        android:layout_width="120dp" 
        android:layout_height="120dp" 
        android:layout_gravity="center" 
        android:layout_marginTop="@dimen/dp8" 
        android:src="@drawable/ic_cars" /> 
      </LinearLayout> 

      <RelativeLayout 
       android:id="@+id/content_view" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" 
       android:layout_marginLeft="@dimen/dp8" 
       android:layout_toRightOf="@+id/img_view"> 

       <TextView 
        android:id="@+id/tv_request_status" 
        style="@style/txtview_standard_widget" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" 
        android:layout_centerHorizontal="true" 
        android:layout_marginBottom="@dimen/dp8" 
        android:text="Pending" 
        android:textColor="@color/colorAccent" /> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/tv_request_status" 
        android:orientation="vertical"> 

        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="@dimen/dp4" 
         android:layout_marginTop="@dimen/dp4" 
         android:weightSum="1"> 

         <TextView 
          style="@style/txtview_standard_widget" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="0.4" 
          android:text="Phone" /> 

         <TextView 
          android:id="@+id/tv_phone_number" 
          style="@style/txtview_standard_widget" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="0.6" 
          android:text="Phone" /> 
        </LinearLayout> 

        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="@dimen/dp4" 
         android:layout_marginTop="@dimen/dp4" 
         android:weightSum="1"> 

         <TextView 
          style="@style/txtview_standard_widget" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="0.4" 
          android:text="Email" /> 

         <TextView 
          android:id="@+id/tv_email" 
          style="@style/txtview_standard_widget" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="0.6" 
          android:text="[email protected]" /> 
        </LinearLayout> 

        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="@dimen/dp4" 
         android:layout_marginTop="@dimen/dp4" 
         android:weightSum="1"> 

         <TextView 
          style="@style/txtview_standard_widget" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="0.4" 
          android:text="Age" /> 

         <TextView 
          android:id="@+id/tv_age" 
          style="@style/txtview_standard_widget" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="0.6" 
          android:text="Phone" /> 
        </LinearLayout> 

        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="4dp" 
         android:layout_marginTop="@dimen/dp4" 
         android:weightSum="1"> 

         <TextView 
          style="@style/txtview_standard_widget" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="0.4" 
          android:text="Gender" /> 

         <TextView 
          android:id="@+id/tv_gender" 
          style="@style/txtview_standard_widget" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="0.6" 
          android:text="Phone" /> 
        </LinearLayout> 

        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="@dimen/dp4" 
         android:layout_marginTop="@dimen/dp4" 
         android:weightSum="1"> 

         <TextView 
          style="@style/txtview_standard_widget" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="0.4" 
          android:text="Efficiency" /> 

         <TextView 
          android:id="@+id/tv_efficiency" 
          style="@style/txtview_standard_widget" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="0.6" 
          android:text="75%" /> 
        </LinearLayout> 
       </LinearLayout> 
      </RelativeLayout> 
     </RelativeLayout> 
    </RelativeLayout> 

</android.support.v7.widget.CardView> 
1

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item > 
     <rotate 
      android:fromDegrees="-45" 
      android:pivotX="0%" 
      android:pivotY="-45%"> 
      <shape android:shape="rectangle"> 
       <solid android:color="#ff0" /> 
      </shape> 
     </rotate> 
    </item> 
</layer-list> 

例:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

    <View 
     android:layout_width="100dp" 
     android:background="@drawable/ssampl" 
     android:layout_height="100dp"> 

    </View> 
</LinearLayout> 
+0

@Muthkrishnan:助けてくれてありがとう。 XMLは正しい形になっていますが、私の見解では同じことをしていません。私は回転を使用しようとしていますが、運はありません。 –

+0

こんにちは、私は私の答えを更新する見ている。 –

関連する問題