简体   繁体   English

如何根据 TextView 的大小改变 BitmapDrawable 的大小?

[英]How to change size of BitmapDrawable in accordance with size of TextView?

I have TextView with background picture in my layout and would like to apply an animation to the text only.我的布局中有带有背景图片的TextView ,并且想仅将 animation 应用于文本。 So, as I was advised in the separate question :因此,正如我在单独的问题中所建议的那样:

you could try embedding a TextView and a BitmapDrawable in a FrameLayout, then apply the animation to the TextView.您可以尝试在 FrameLayout 中嵌入 TextView 和 BitmapDrawable,然后将 animation 应用于 TextView。

So, the question is what should be the layout that BitmapDrawable size would be changed in accordance with TextView size always?那么,问题是, TextView BitmapDrawable大小而改变的布局应该是什么?

Try setting the drawable on the FrameLayout itself.尝试在 FrameLayout 本身上设置可绘制对象。 The FrameLayout will be the same size as the text, because of wrap_content, and so the background will be as well.由于 wrap_content,FrameLayout 将与文本大小相同,因此背景也是如此。 The animation should only affect the drawing, not the actual layout, so this should still work when you animate it. animation 应该只影响绘图,而不是实际布局,所以当你为它设置动画时它应该仍然有效。

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/your_background">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World" />
</FrameLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM