2014-02-08 73 views
0

我要在Android中創建一個具有圓形形狀的提醒對話框。 我遵循這個網站的許多線程。創建shape.xml,並把它繪製資源Android:將圓形形狀應用於線性佈局

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle"> 
<stroke android:width="5dp" android:color="#FF0000" /> 
<corners android:bottomRightRadius="20dp" android:bottomLeftRadius="20dp" 
android:topLeftRadius="20dp" android:topRightRadius="20dp"/> <solid android:color="#FFFF00"/> 

和上面的形狀適用於LinearLayout中。 layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:background="@android:color/transparent" > 

<LinearLayout android:layout_width="200dip" 
    android:layout_height="60dip" 
    android:orientation="vertical" 
    android:background="@drawable/shape"> 

</LinearLayout> 

不過,目前仍然有對話框外的矩形邊框和背面的顏色。這不是我想要的。 我有很長一段時間的搜索,我不知道如何解決它。 我的目標是讓它在對話框佈局的角落之外透明。非常感謝!

屏幕截圖:http://postimg.org/image/3xbnmquyt/

+0

你能張貼那張圖嗎? –

+0

就像[http://openclipart.org/people/rg1024/rg1024_set_of_eight_rounded_shapes.svg](this)中間一個的左邊。謝謝。 – dsafajw

回答

1

對於要我找到了一個默認的Android Studio形狀,這樣的:

android:background="@drawable/abc_menu_dropdown_panel_holo_light" 

它應用到你的LinearLayout,這是exatcly你talikng關於什麼的,您不需要在drawables中創建其他xml文件。看看它是什麼樣子看到我的答案在這裏: Android View shadow

希望我幫你。

+0

感謝您的評論。對不起,我可能會將您從上面的代碼中混淆。我其實想要塑造這樣的形狀[鏈接](http://openclipart.org/detail/27891/set-of-eight-round-shapes-by-rg1024-27891)。我最終得到了正確的形狀,但角落外面有一種黑色。希望你明白我的意思。謝謝。 – dsafajw

0

刪除中風標籤,因爲它用於創建邊框。此外,你不應該使用漸變和堅實,因爲他們排除對方。

http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

+0

是的,我需要創建一個與圓角對齊的邊框。但現在在角落外面有一種黑色。我想讓它透明。 – dsafajw

+0

好吧,如果您發佈佈局xml的代碼會容易得多,但我認爲您應該將您的LinearLayout放在具有相同尺寸但不是圓角的另一個佈局中,並將此容器佈局的顏色設置爲透明或甚至更好地設置與背景相同的顏色。 – mishasrb

+0

我已編輯我的帖子和附加的代碼。感謝您的幫助!! – dsafajw