2011-11-04 140 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