20

webView の角を丸くしようとしています。

これが私のコードです:

rounded_webview.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
 <solid android:color="#000"/>
    <corners
     android:bottomRightRadius="15dp"
     android:bottomLeftRadius="15dp"
  android:topLeftRadius="15dp"
  android:topRightRadius="15dp"/>
</shape>

そして、ここに私のwebViewがあります:

<WebView
        android:id="@+id/webView1"
        android:layout_width="293dp"
        android:layout_height="142dp"
        android:layout_gravity="center_horizontal"
        android:padding="5dip"
        android:background="@drawable/rounded_webview"/>

しかし、それは単にうまくいきません!角が丸くない…

4

6 に答える 6

26

これは Webview のちょっとした癖です。デフォルトの背景色は白で、ドローアブルの前に描画されます。透明にして描画可能な背景を表示するには、次のコードを使用する必要があります。

WebView webview = (WebView)findViewById(R.id.webView1);        
webview.setBackgroundColor(0);
于 2012-08-13T02:08:09.070 に答える
18

唯一の方法は、WebView 要素を他のビュー (FrameLayout など) でラップし、外部ビューに丸みを帯びた角の背景を適用することです。例:

<FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="10dip"
        android:paddingBottom="10dip"
        android:paddingLeft="1dip"
        android:paddingRight="1dip"
        android:background="@drawable/white_rounded_area"
        >
    <WebView
            android:id="@+id/web_view"
            android:layout_width="300dip"
            android:layout_height="400dip"
            android:layout_gravity="center"
            />
</FrameLayout>

paddingTopとpaddingBottomはdrawable /white_rounded_areaからの半径に等しく、 paddingLeftpaddingRightは drawable /white_rounded_areaのストローク幅に等しくなります。

このアプローチの欠点は、特にページがスクロールされたときに、上部と下部の丸いパネルが WebView 内の Web ページで異なる背景色を持つ可能性があることです。

于 2012-09-19T09:07:18.150 に答える
4

これを試して

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
         android:shape="rectangle" >

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

      <stroke
        android:color="@drawable/black"
        android:width="3dp"/>

</shape>
于 2012-07-26T18:18:59.017 に答える