drawable - android: fit height of DrawableLeft in a textView -
i trying display blue line next block of text, pretty this:
here's code:
<textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableleft="@drawable/blue_line" />
blue_line jpg file. blue rectangle. displays in original size regardless of text in textview. how can adjust height dynamically according height of text? make shorter when theres little amount of text , longer when there's more text....
you can try doing in code setting bounds image
textview1.getviewtreeobserver() .addongloballayoutlistener(new ongloballayoutlistener() { @override public void ongloballayout() { drawable img = activityname.this.getcontext().getresources().getdrawable( r.drawable.blue_line); img.setbounds(0, 0, img.getintrinsicwidth() * textview1.getmeasuredheight() / img.getintrinsicheight(), textview1.getmeasuredheight()); textview1.setcompounddrawables(img, null, null, null); textview1.getviewtreeobserver().removeongloballayoutlistener(this); } });
Comments
Post a Comment