如何在Android中使用BitMap进行以下设计?

时间:2015-10-24 06:29:47

标签: java android canvas bitmap android-bitmap

我刚刚开始使用Bitmap,想尝试设计一下这个按钮:

enter image description here

我正在使用SpannableString进行进一步处理。如何使用Bitmap

获得圆角的此类形状

1 个答案:

答案 0 :(得分:0)

试试这个,

活动中的位图使用

package com.example.testproject;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;

public class TestImages extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ImageView image = (ImageView) findViewById(R.id.test_image);
        Bitmap bMap = BitmapFactory.decodeFile("/sdcard/test2.png");
        image.setImageBitmap(bMap);
    }
}

对于圆形图片,请尝试以下代码

rounded_corner.xml

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <!-- view background color -->
    <solid android:color="#ffffff" >
    </solid>

    <!-- view border color and width -->
    <stroke
        android:width="1dp"
        android:color="#1c1b20" >
    </stroke>

    <!-- If you want to add some padding -->
    <padding
        android:bottom="4dp"
        android:left="4dp"
        android:right="4dp"
        android:top="4dp" >
    </padding>

    <!-- Here is the corner radius -->
    <corners android:radius="10dp" >
    </corners>

</shape>

将此文件添加到可绘制文件夹

<强> main_activity.xml

将此行添加到XML中的textview

android:background="@drawable/rounded_corner"