【问题标题】:How to draw rectangle frame in android [duplicate]如何在android中绘制矩形框[重复]
【发布时间】:2018-02-08 14:38:32
【问题描述】:

每次可以用的时候我都想画一个正方形。显示的条形码仅具有代表性。我想画一幅画,我可以像图片一样给出正方形的尺寸。我怎样才能做到这一点 ?我可以研究什么?我想通过将编写的 MainActivity 类中的度量分配给特定类来做到这一点。

enter image description here

enter image description here

【问题讨论】:

    标签: android canvas android-drawable rectangles


    【解决方案1】:

    使用以下 xml 制作可绘制对象:

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

    这将生成一个纯黑色矩形,如果您想要一个带有边框的矩形,请改用以下代码:

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >
        <solid android:color="#000000" />
        <stroke android:color="#c4441d" android:width="5dp" />
    </shape>
    

    一旦你制作了drawable,就说rect.xml。您可以在布局中使用它,如下所示:

    <ImageView
       android:layout_width="100dp"
       android:layout_height="50dp"   
       android:src="@drawable/rect" />
    

    更多详情:http://devdeeds.com/how-to-create-rectangle-shape-using-xml-in-android/

    如果您想在代码中执行此操作,请查看此现有问题:Android canvas draw rectangle

    【讨论】:

    • 我写的和你写的一样吗?你给我发张照片吗
    猜你喜欢
    • 1970-01-01
    • 2020-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-13
    • 2011-08-02
    • 1970-01-01
    相关资源
    最近更新 更多