2012-11-23 19 views
0

我有一個彈出窗口顯示在我的xml中。它應該有一個邊框。以下是代碼: -如何在android xml中使用圖像作爲邊框

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/rl_parent" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:paddingBottom="20dp" > 
<RelativeLayout 
    android:id="@+id/rl_startpopup" 
    android:layout_width="340dp" 
    android:layout_height="320dp" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:background="@drawable/popup_outline" 
    android:orientation="vertical" />  
</RelativeLayout> 

的popup_outline的形狀

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" > 
<gradient 
    android:angle="270" 
    android:endColor="#192423" 
    android:startColor="#4a7669" 
    android:type="linear" /> 
<corners android:radius="8dp" /> 
<stroke 
    android:width="2dp" 
    android:color="#e4f4d3" /> 
</shape> 

這裏彈出窗口的圖像: -

enter image description here

這種 「popup_outline」 是白顯示邊框。我想使用可重複的圖案圖像而不是一種顏色作爲邊框。我必須在xml中執行此操作。請幫助

回答

0

您可以使用FrameLayout來顯示邊框,並在FrameLayout中使用ImageView或RelativeLayout來顯示其他內容。

例子: -

<FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/IMAGE_OF_YOUR_CHOICE_WITH_repeatable pattern" 
     > 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      ></RelativeLayout> 
    </FrameLayout> 
0

你可以使用任何佈局使用邊界,裏面的佈置您可以自由使用任何視圖或佈局如TextView的,ImageView的

例子: -

<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/popupbox" android:padding="50dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Your Garage is empty" /> </RelativeLayout>