标签: android-shapedrawable

圆角视图不平滑

看看下面的代码.

ShapeDrawable shapeDrawable = new ShapeDrawable(new RectShape());
    shapeDrawable.getPaint().setColor(Color.parseColor("#5a2705"));
    shapeDrawable.getPaint().setStyle(Style.STROKE);
    shapeDrawable.getPaint().setAntiAlias(true);
    shapeDrawable.getPaint().setStrokeWidth(2);
    shapeDrawable.getPaint().setPathEffect(new CornerPathEffect(10));
Run Code Online (Sandbox Code Playgroud)

我将此作为背景应用于我LinearLayout,但边缘不平滑.我怎样才能解决这个问题?

以下是它的外观截图.

在此输入图像描述

android rounded-corners android-shapedrawable

3
推荐指数
1
解决办法
1800
查看次数

Android 上模糊的 1dip 形状线(边框)

这是我的应用程序的屏幕截图:

在此处输入图片说明

它取自Samsung Galaxy Note10.1 ( mdpi149 ppi)。

我的客户认为底部按钮周围的边界线和上面的圆角矩形是模糊的。

我使用形状作为背景,看起来像这样:

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

    <stroke android:width="1dp" android:color="@color/dark_gray" />

    <solid android:color="@color/sepia_bright" />

</shape>
Run Code Online (Sandbox Code Playgroud)

当我使用简单视图作为 1dp 高度的线时:

<View
    android:background="@color/bright_gray"
    android:layout_width="match_parent"
    android:layout_height="1dp" />
Run Code Online (Sandbox Code Playgroud)

正如您在下一个屏幕截图中看到的那样,它非常清晰:

在此处输入图片说明

简单的水平线没问题,但图形周围的矩形再次模糊。

我究竟做错了什么?

谢谢你的帮助。

android android-shapedrawable

3
推荐指数
1
解决办法
1929
查看次数

自定义形状(圆角正方形)可绘制的android

我想要自定义形状边框,如下所示:

在此处输入图片说明

这是我迄今为止尝试过的:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#00000000"/>
    <stroke android:width="0.1dp" android:color="#FFFFFF" />
    <corners android:radius="5dp"/>
    <!--<padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" />-->
</shape>
Run Code Online (Sandbox Code Playgroud)

但这并没有给我弯曲的侧面,只有弯曲的角落。

我需要弯曲的侧面

android xml-drawable android-canvas android-drawable android-shapedrawable

2
推荐指数
1
解决办法
6173
查看次数

如何为工具栏制作圆角?

我看过其他答案,它们都适用于操作栏而不是工具栏,并且它们需要创建新形状。

有没有一种简单的方法可以使用 来做到这一点styles.xml

android android-layout android-toolbar android-shapedrawable material-components-android

2
推荐指数
1
解决办法
5597
查看次数

如何将浮动操作按钮用作正方形?

有很多 SO 线程说他们的按钮显示为一个错误的正方形

方形浮动操作按钮

带有 Android 设计库的 Square FloatingActionButton

显示为正方形的浮动操作按钮

但是我的目标是使用方形按钮。怎么circle floating action button改成方形的?

<com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"     
        android:backgroundTint="@color/standardBlue"
        app:srcCompat="@drawable/ic_3d_model"/>
Run Code Online (Sandbox Code Playgroud)

android floating-action-button android-shapedrawable material-components material-components-android

1
推荐指数
1
解决办法
522
查看次数

Android Canvas:创建 RoundRectShape 对象

我为矩形创建了一个类,因为它是我的应用程序中的一个对象。但是现在我希望角落是圆的。在下面你可以看到它是一个简单的骨骼类,用于创建我想要的具有相同属性的任意数量的矩形。

public class customDrawable extends ShapeDrawable {

    public void setCustomDrawableAttributes(ShapeDrawable shapeDrawable){
       int x = 0;
       int y = 0;
       int width = 100;
       int height = 100;
       shapeDrawable.setBounds(x, y-height, x + width,y+height );
   }

   public ShapeDrawable createShape(){
       return new ShapeDrawable(new RectShape());
   }

}
Run Code Online (Sandbox Code Playgroud)

更新:如果没有这种方法,我将无法绘制任何内容,因为没有大小。有了它,它只绘制通常的矩形。(更改为不显示特定于应用程序的方法的整数值)

public void setDrawableAttributes(ShapeDrawable shapeDrawable){
   int x = 0;
   int y = 500
   int width = 200
   int height = 300
   shapeDrawable.setBounds(x, y-height, x + width,y+height );
Run Code Online (Sandbox Code Playgroud)

}

从我的研究中,我发现我不能简单地添加圆角,而是必须创建一个RoundRectShape shapeDrawable. 我使用此方法创建带圆角的矩形的每次尝试都RoundRectShape失败了。不知何故,形状总是最终成为一个没有圆角的规则矩形。

我正在寻找一个简单的骨骼类(就像提供的那个),它创建一个 roundRectShape …

java android android-canvas shapedrawable android-shapedrawable

0
推荐指数
1
解决办法
3329
查看次数

-2
推荐指数
1
解决办法
832
查看次数