0

Now I need to implement a function just like the html tag , see the pic below:

the currect showing

Firstly, I set the drawableLeft, and it show like this:

the unclect showing

It's not my suppose do. After that I create a class 'LiTextView' implements TextView, and override the onDraw() method like this:

@Override
protected void onDraw(Canvas canvas) {
    Drawable[] drawables = getCompoundDrawables();
    if (drawables != null) {
        Drawable drawableLeft = drawables[0];
        if (drawableLeft != null) {
            canvas.save();
            canvas.translate(10, 50);
            drawableLeft.draw(canvas);
            canvas.restore();
        }
    }
    super.onDraw(canvas);
}

the xml file like this:

<me.naiyu.android.textviewlidemo.widget.LiTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:drawableLeft="@drawable/circle_dot"
        android:drawablePadding="10dp"
        android:textColor="#000000"
        android:textSize="18sp"
        android:text="Displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing"/>

and it became this(have two circle):

enter image description here

How can I implement the picture one, I now have no idear!

Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45
naiyu
  • 745
  • 3
  • 9
  • 25
  • 2
    I would have used a RelativeLayout with ImageView and TextView inside it, in order to align it like you want. – Carnal Feb 03 '15 at 13:44
  • I now implement it as you say., but I have a question that how can I align the ImageView just center to the TextView's first line, if there have many lines? – naiyu Feb 04 '15 at 01:33
  • I dont really understand what you mean. – Carnal Feb 04 '15 at 08:32
  • I need the circle align the center of the TextView's fisrt line. just line the html tag
  • – naiyu Feb 05 '15 at 08:05
  • You will have to set some android:layout_marginTop on the ImageView – Carnal Feb 05 '15 at 08:37