Code Monkey home page Code Monkey logo

Comments (12)

jtadiarca avatar jtadiarca commented on July 25, 2024

This is the same issue as issue#78.
Quoted from the answer in isssue#78: "You don't need to use RoundedImageView since TextDrawable already supports rounded corners. Just use a normal ImageView."

from textdrawable.

caraus avatar caraus commented on July 25, 2024

This is exactly what I was trying to Say Zeph.

from textdrawable.

rachitmishra avatar rachitmishra commented on July 25, 2024

@zephzeph what if I want to load the image from web, if not then use TextDrawable

from textdrawable.

niteshreddy avatar niteshreddy commented on July 25, 2024

@byandby @zephzeph @caraus @rachitmishra
Hi,
I am using CircleImageView which is a derivative of RoundedImageView, I have not been able to use this library because Bitmap#createBitmap thrown this exception. java.lang.IllegalArgumentException: width and height must be > 0 . Have you guys been able to find a solution to this while using the CircleImageView?

from textdrawable.

rachitmishra avatar rachitmishra commented on July 25, 2024

ok! awesome, will use that!

from textdrawable.

KtodaZ avatar KtodaZ commented on July 25, 2024

I've got it working with CircleImageView (https://github.com/hdodenhof/CircleImageView).

What I did was set the TextDrawable to a scale of the length/width of my CircleImageView. For example my CircleImageView is L:56 W:56. I set the TextDrawable to L:112 and W:112 and converted the TextDrawable to a bitmap. Then I passed the bitmap to the CircleImageView.

from textdrawable.

divonas avatar divonas commented on July 25, 2024

@KtodaZ How exactly do you set L, W? setIntrinsicWidth(500) doesn't seem to work. Would you mind sharing your solution?

from textdrawable.

KtodaZ avatar KtodaZ commented on July 25, 2024

Sure. Here is my code below:

 private final int circleImageViewWidth = 112;
 private final int circleImageViewTextSize = 60;
// Create drawable
TextDrawable drawable = TextDrawable.builder(this)
                .beginConfig()
                .useFont(Typeface.DEFAULT_BOLD)
                .fontSize(circleImageViewTextSize)
                .height(circleImageViewWidth)
                .width(circleImageViewWidth)
                .endConfig()
                .buildRound(Character.toString(firstName.charAt(0)).toUpperCase(), color);
// Convert to bitmap (generic solution found on stackoverflow)
if (drawable instanceof BitmapDrawable) {
            BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
            if(bitmapDrawable.getBitmap() != null) {
                return bitmapDrawable.getBitmap();
            }
        }

        if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
            bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
        } else {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        }

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;

and my recycler_text_view.xml

<de.hdodenhof.circleimageview.CircleImageView
                        android:id="@+id/circleImageView"
                        android:layout_width="56dp"
                        android:layout_height="56dp"
                        android:src="@drawable/ic_contact_picture" />

@divonas Hope this helps

from textdrawable.

divonas avatar divonas commented on July 25, 2024

@KtodaZ Thank you for sharing.

from textdrawable.

divonas avatar divonas commented on July 25, 2024

For anyone having problems with RoundedImageView, just set width and height in the TextDrawable builder. This way the RoundedImageView will be able to display it.

from textdrawable.

cobear25 avatar cobear25 commented on July 25, 2024

@divonas you rock, setting the height and width is all that's needed. I'm using com.makeramen.roundedimageview.RoundedImageView

from textdrawable.

shastrikikitchen avatar shastrikikitchen commented on July 25, 2024

text color is not set even after setting the color
alPha = TextDrawable.builder() .beginConfig() .height(40) .width(40) .useFont(ViewUtils.getMontesaratfont()) .textColor(R.color.white) .endConfig() .buildRound(letter, generator.getColor(position)); this is my code

from textdrawable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.