矩形的边框转角半径是不完美的(Android的形状) [英] Rectangle's corner border radius is not perfect (Android Shape)
问题描述
我试图创建圆角半径和边框android上的矩形形状。我几乎做到了,只是我不能解到现在为止一个小问题:
I tried to create a rectangle shape with corner radius and border on android. I almost made it, just a little problem that i cant solve until now :
边界已经在其拐角半径一些,但内部矩形不(请参阅图像上的红色标记)。
The border already has some radius on its corner, but the inner rectangle does NOT (please see the red mark on the image).
这是我的code:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp"/>
<stroke android:width="3dp" android:color="#000000" />
</shape>
我用这个形状用的android:SRC
在的ImageView
。
这是我如何使用形状:
<ImageView
android:src="@drawable/rectangle"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
这就是我如何保持体形的大小(我的适配器上):
And this is how i maintain the shape's size (on my adapter) :
holder.answer.setBackgroundColor(getItem(position).getColor());
holder.answer.getLayoutParams().width = (int) GlobalUtil.size;
holder.answer.getLayoutParams().height = (int) GlobalUtil.size;
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(holder.answer.getLayoutParams());
lp.setMargins(0, (int) GlobalUtil.gapGrid, 0, (int) GlobalUtil.gapGrid);
holder.answer.setLayoutParams(lp);
请好心帮我,谢谢你。
推荐答案
使用的android:背景
而不是的android:SRC
因为现在它是根据密度应用的缩放比例。
Use android:background
instead of android:src
because right now it is applying scaling according to density.
编辑:
rectangle.xml
rectangle.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp"/>
<stroke android:width="3dp" android:color="#00FF00" />
的ImageView
ImageView
<ImageView
android:background="@drawable/rectangle"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Java的code:
Java code:
//holder.answer.setBackgroundColor(getItem(position).getColor());
holder.answer.getLayoutParams().width = (int) GlobalUtil.size;
holder.answer.getLayoutParams().height = (int) GlobalUtil.size;
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(holder.answer.getLayoutParams());
lp.setMargins(0, (int) GlobalUtil.gapGrid, 0, (int) GlobalUtil.gapGrid);
holder.answer.setLayoutParams(lp);
这篇关于矩形的边框转角半径是不完美的(Android的形状)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!