2017-04-08 231 views
2

我需要動態地設置一個GridView項目,我使用LinearLayout與應用圓角的背景可繪製,但我不知道如何設置像這張圖片只有左上角的邊框顏色。 ... ExampleAndroid的圓形邊框顏色左上角只有dinamically

<img src="https://i.stack.imgur.com/R8lyH.png"/>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/gridview_item" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/btn_rounded_white" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/gridview_text" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:clickable="true" 
      android:text="@string/app_name" 
      android:textSize="@dimen/gridview_text" 
      android:textStyle="bold" 
      android:layout_gravity="center" 
      android:gravity="center"> 

     </TextView> 

    </LinearLayout> 


<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 
    <solid android:color="@color/griditem_cat" /> 
    <padding android:left="5dp" 
     android:top="5dp" 
     android:right="5dp" 
     android:bottom="5dp"/> 
    <corners android:bottomRightRadius="7dp" 
     android:bottomLeftRadius="7dp" 
     android:topLeftRadius="7dp" 
     android:topRightRadius="7dp"/> 
</shape> 
+0

要dyanmically設置左上角的顏色,或者你只能擁有這四種顏色? –

+0

@Aditya Vyas-Lakhan它需要使用十六進制顏色動態着色,我嘗試使用三角形自定義視圖,但是我失去了圓角左上角,如動態顯示的圖像示例 –

+0

,您需要調用「Drawable#setColorFilter」你的「三角形」可繪製 – pskink

回答

0

什麼是這樣的:設置一個相對佈局,並把一個ImageView的你繪製的左上方

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/gridview_item" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

      <ImageView 
       android:layout_width="5dp" 
       android:layout_height="5dp" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:src="@drawable/btn_rounded_white" 
       /> 

     <TextView 
      android:id="@+id/gridview_text" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:clickable="true" 
      android:text="@string/app_name" 
      android:textSize="@dimen/gridview_text" 
      android:textStyle="bold" 
      android:layout_centerInParent="true" 
      android:gravity="center"> 

     </TextView> 

    </RelativeLayout> 
+0

它需要動態顏色我的朋友多數民衆贊成的問題,我曾想過ImageView,但顏色需要動態設置十六進制... –

+0

welll,可以做到圖像視圖! –

0

grid_item.xml

<RelativeLayout 
android:id="@+id/gridview_item" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
    <PinnedGridItemView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
    <TextView android:id="@+id/gridview_text"> 
    </TextView> 
</RelativeLayout> 

CategoryAdapter

pin = (PinnedGridItemView) relativeLayout.findViewById(R.id.pinned_grid_item); 
pin.setColorCode(Color.RED);// Here I set any color that I want dynamically, the problem now is to solve top-left rounded corner 

Result image