Search in sources :

Example 1 with SimpleDraweeSpanTextView

use of com.facebook.drawee.span.SimpleDraweeSpanTextView in project fresco by facebook.

the class DraweeSpanSimpleTextFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    SimpleDraweeSpanTextView draweeSpanTextView = (SimpleDraweeSpanTextView) view.findViewById(R.id.drawee_text_view);
    // The # will be replaced with the image.
    String text = getString(R.string.drawee_span_simple_text);
    int imagePosition = text.indexOf('#');
    DraweeSpanStringBuilder draweeSpanStringBuilder = new DraweeSpanStringBuilder(text);
    DraweeHierarchy draweeHierarchy = GenericDraweeHierarchyBuilder.newInstance(getResources()).setPlaceholderImage(new ColorDrawable(Color.RED)).build();
    DraweeController controller = Fresco.newDraweeControllerBuilder().setUri(INLINE_IMAGE_URI).build();
    draweeSpanStringBuilder.setImageSpan(getContext(), /* Context */
    draweeHierarchy, /* hierarchy to be used */
    controller, /* controller to be used to update the hierarchy */
    imagePosition, /* image index within the text */
    200, /* image width */
    200, /* image height */
    false, /* auto resize */
    DraweeSpan.ALIGN_CENTER);
    /* alignment */
    draweeSpanTextView.setDraweeSpanStringBuilder(draweeSpanStringBuilder);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) DraweeController(com.facebook.drawee.interfaces.DraweeController) SimpleDraweeSpanTextView(com.facebook.drawee.span.SimpleDraweeSpanTextView) DraweeSpanStringBuilder(com.facebook.drawee.span.DraweeSpanStringBuilder) DraweeHierarchy(com.facebook.drawee.interfaces.DraweeHierarchy)

Aggregations

ColorDrawable (android.graphics.drawable.ColorDrawable)1 DraweeController (com.facebook.drawee.interfaces.DraweeController)1 DraweeHierarchy (com.facebook.drawee.interfaces.DraweeHierarchy)1 DraweeSpanStringBuilder (com.facebook.drawee.span.DraweeSpanStringBuilder)1 SimpleDraweeSpanTextView (com.facebook.drawee.span.SimpleDraweeSpanTextView)1