2011-11-04 139 views
1

我有LinearLayoutshape背景和WebView裏面。如何沿着形狀的邊界切割WebView?如何削減子佈局的邊界?

我想讓WebView適合形狀,所以WebView不會有任何銳角。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:padding="5dip" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/bg_border" 
    android:orientation="vertical" > 

    <WebView android:id="@+id/webview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 

    </LinearLayout> 
</LinearLayout> 

bg_border.xml

<?xml version="1.0" encoding="utf-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 
<stroke 
    android:width="1dp" 
    android:height="1dp" 
    android:color="@color/border" /> 

<corners 
    android:radius="5dp" 
    android:bottomRightRadius="5dp" 
    android:bottomLeftRadius="5dp" 
    android:topLeftRadius="5dp" 
    android:topRightRadius="5dp" /> 

enter image description here

回答

0

我敢打賭,你只能模擬這一點。創建另一個具有(較小)半徑的形狀,並使其變爲白色。把它放在你的web視圖中。如果您正在查看的頁面不是白色,這顯然不起作用。

此外,如果您已經定義了「radius」並且所有值都相同,則不需要定義topLeft/bottomRight/etc。

UPDATE 想法。他們都涉及一個源圖像像這樣:http://www.noiseindustries.com/downloads/misc/FxFactoryHelp/pluginguide/generators/roundedrectangle/files/ni-rounded-rectangle.jpg

只要確保邊界更小。 3-5像素。白色中心應該是透明的,而不是白色的。

1)創建一個RelativeLayout,併爲邊角創建圖像。通過佈局和圖像,基本佈置圖像,以便「繪製」邊框。不要在中心放置任何東西。創建一個FrameLayout,放入webview,然後把RelativeLayout放在最前面。希望中心的觸摸事件可以通過webview,但仍然會給你一個邊緣的柔和邊框。

2)創建一個基本看起來與1中描述的邊界相同的9補丁圖像。執行1中描述的相同FrameLayout,並添加Webview。最重要的是,添加一個CUSTOM視圖。將背景設置爲9修補程序,並確保自定義視圖傳遞所有觸摸事件。

我懷疑#1會更容易實施,但誰知道?

+0

頁面的顏色會改變,所以它不是我的方式。 感謝您對「radius」的評論。 – Sviatoslav

+0

我會選擇第一個。 我認爲有一個更簡單的方法:) – Sviatoslav