2012-05-08 33 views
2

我需要在我的應用中爲圖像視圖或文本視圖繪製邊框,但是我需要僅在一個角落繪製邊框,如圖像。在Android中的一個角落繪製半徑邊框到imageview或textview中的一個角落

enter image description here

我做一個形狀,但我在所有4個方面得到邊界:

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <stroke android:width="1px" android:color="#FF000000" /> 
    <solid android:color="#ffffffff"/> 
    <padding android:left="1px" android:top="1px" 
     android:right="0px" android:bottom="0px" /> 
    <corners android:topLeftRadius="8px" /> 
</shape> 

我如何做形象使它像?

感謝,馬蒂亞

回答

6

使用此代碼將解決這個問題:

<?xml version="1.0" encoding="utf-8" ?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
    <shape android:shape="rectangle"> 
    <solid android:color="#FF0000" /> 
    <corners android:topLeftRadius="15dp" /> 
    </shape> 
</item> 
<item android:left="10dp" android:top="10dp"> 
    <shape android:shape="rectangle"> 
    <solid android:color="#000000" /> 
    <corners android:topLeftRadius="15dp" /> 
    </shape> 
</item> 
</layer-list> 

你必須做出的(佈局XML)的調整也爲:

的android:layout_width

android:layout_height

android:paddingTop

的android:paddingLeft

這是輸出:

enter image description here

希望這有助於。

+0

@pindol 你檢查它,它的測試,並與我一起工作 –

+0

沒有對我來說doesen't工作,這裏是我所看到的:http://mattialori.net/imageview.png – pindol

+0

@pindol請檢查更新回答 –

0

這就是我的成就。使用inset可繪製的,我們可以實現這個輕鬆和更多的定製,我們可以用更少的代碼來完成。使用此twoside_border.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!-- inset: It can remove border from any other side--> 
<inset xmlns:android="http://schemas.android.com/apk/res/android" 
android:insetBottom="-15dp" 
android:insetRight="-15dp"> 

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/rectangle"> 
    <stroke 
     android:width="20dp" 
     android:color="#ED302F" /> 

    <!--<corners 
     android:topLeftRadius="20dp" 
     />--> 

    <!--<solid android:color="#f50a0a" />--> 
</shape> 

insetBottom & insetRight-dp值有助於隱藏的邊界,我們並不需要,並作爲輸出:

two side border image

以獲得角球曲線刪除上面代碼中的註釋行

<corners android:topLeftRadius="20dp"/> 

現在我們可以看到類似下面我怎麼&根據您的需要調整填充或利潤率曲線彎曲

border with curve image

使用此xmlframe layout,使其適合邊框內圖像看起來像一個框架。

<FrameLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 

       android:paddingLeft="5dp" 
       android:paddingRight="5dp" 
       android:paddingTop="5dp" 
       android:scaleType="centerCrop" 
       android:src="@drawable/your_image_file" /> 

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="@drawable/twoside_border" /> 

     </FrameLayout>