Eam*_*orr 13 java android rounded-corners
我试图给我的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>
Run Code Online (Sandbox Code Playgroud)
这是我的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"/>
Run Code Online (Sandbox Code Playgroud)
但它根本行不通!角落不圆......
提前谢谢了,
geo*_*sey 21
这是Webview的一个小怪癖,它有一个白色的默认背景颜色,绘制在任何drawable之前.您需要使用以下代码使其透明并显示您的可绘制背景:
WebView webview = (WebView)findViewById(R.id.webView1);
webview.setBackgroundColor(0);
Run Code Online (Sandbox Code Playgroud)
iBo*_*Bog 16
唯一的方法是通过其他视图(例如FrameLayout)包装WebView元素,并在外部视图上应用圆角背景.例:
<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>
Run Code Online (Sandbox Code Playgroud)
其中paddingTop和paddingBottom等于drawable/white_rounded_area的半径, paddingLeft和paddingRight等于笔画宽度drawable/white_rounded_area.
这种方法的缺点是顶部底部圆形面板可以与WebView内的网页具有不同的背景颜色,尤其是在页面滚动时.
你可以使用 CardView 来包含 webview,你只需要添加你想要的圆角半径app:cardCornerRadius:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="10dp"> // HERE
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
就这样
| 归档时间: |
|
| 查看次数: |
7975 次 |
| 最近记录: |