Java Android:提供圆角的网络视图?
我正试图让我的网络视图更圆 这是我的密码: rounded_webview.xml:Java Android:提供圆角的网络视图?,java,android,rounded-corners,Java,Android,Rounded Corners,我正试图让我的网络视图更圆 这是我的密码: 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"/>
<?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
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"/>
但这根本不起作用!角不圆…试试这个
<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>
这是Webview的一个小怪癖,它有一个默认的白色背景色,绘制在任何可绘制内容的前面。您需要使用以下代码使其透明并显示可绘制的背景:
WebView webview = (WebView)findViewById(R.id.webView1);
webview.setBackgroundColor(0);
唯一的方法是通过其他视图(例如FrameLayout)包裹WebView元素,并在外部视图上应用圆角背景。 例如:
其中,填充顶部和填充底部等于可拉伸/白色圆形区域的半径,
paddingLeft和paddingRight等于笔划宽度可绘制/白色圆形区域
这种方法的缺点是顶部和底部的圆形面板可以与WebView内的网页具有不同的背景颜色,尤其是当网页滚动时 我使用了一个看起来像画框的图像,在这里我给画框加上了圆角。我把这个相框放在视图上,我试图给它圆角 这克服了背景面板工作不好的问题
诀窍是使用
相对值yout
;把你的布局放在里面。
在布局下方,添加另一个ImageView
,将其背景设置为合适的遮罩图像框。这将在其他布局的顶部绘制
在我的例子中,我制作了一个9Patch文件,它是一个灰色背景,带有一个透明的圆形矩形
这为基础布局创建了完美的遮罩
XML代码可以是这样的:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<!-- ... INSERT ANY VIEW HERE ... -->
<!-- FRAME TO MASK UNDERLYING VIEW -->
<ImageView android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="@drawable/grey_frame"
android:layout_alignTop="@+id/mainLayout"
android:layout_alignBottom="@+id/mainLayout" />
</RelativeLayout>
有关详情,请参阅我原来的答覆:
没有一种解决方案适合我。
这对我有用。在加载数据之前,您需要设置
webView.getSettings().setUseWideViewPort(true);
并且,您可以在XML文件中绘制
这对我很有用。您可以使用CardView来包含网络视图,您只需使用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>
//这里
仅此而已您可以尝试在webView上添加一个圆形虚拟视图。。。因此,它将保持更高的层次,看起来更全面。imho最干净的解决方案是实现一个WebView类。我在这里发布了一个简单的复制粘贴解决方案:简单地在WebView上设置背景和填充在技术上是正确的方法,这个建议的答案在技术上只是一个解决方法。但是,这种“正确的方法”不起作用,因为存在一个bug:
<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>