我不知道如何在其消息框中执行类似Whatsapp或Telegram的操作。无论它们多大,它们总是看起来不错,与您发送的文本有关。
我试图自己做,我拍了这张照片:
现在,我在我的应用程序中使用它:(它另存为chat_bubble.png)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_marginRight="0dp"
android:id="@+id/list_item"
android:gravity="right">
<LinearLayout
android:id="@+id/row_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="5dip"
android:background="@drawable/chat_bubble"
android:orientation="horizontal"
android:singleLine="false" >
<TextView
android:id="@+id/list_item_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:paddingLeft="5dp"
android:text="ProgramTitle"
android:textColor="@android:color/white"
android:textSize="20sp" />
<ImageView
android:id="@+id/messageIcon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginTop="15dp"
android:layout_marginRight="10dp"
android:padding="2dp"
android:src="@drawable/wait" />
</LinearLayout>
</LinearLayout>
这是我的ListView中每个ListItem的布局。看起来像这样:
但是,如果我使用较长的文字,则图片会被拉长,因此看起来不再合适:
现在我的问题是,怎么可能没有这个问题。有什么好主意要解决此问题吗?太棒了。
您应该从图像创建一个9补丁。
请参阅Android Dev上的本教程。站点:http://developer.android.com/tools/help/draw9patch.html
在9补丁图像中,您声明图像的哪些部分是“可拉伸的”,哪些部分不是。它基本上是.png图像,其中图像的1 px部分告诉Android,以拉伸此部分。您应该将图像保存在drawable
名为的目录中something.9.png
,并且可以将其称为@drawable/something
。
Android SDK包含一个小程序,可从普通图像创建9补丁图像。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句