当前位置: 代码迷 >> Android >> 如何在Android中使用BitMap进行后续设计?
  详细解决方案

如何在Android中使用BitMap进行后续设计?

热度:46   发布时间:2023-08-04 11:39:14.0

我刚刚开始使用Bitmap并且想要尝试设计一些此按钮:

我正在使用SpannableString进行进一步的处理。 如何使用Bitmap获得带有圆角的这种形状?

尝试这个,

活动中的位图用法

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"
  相关解决方案