Ani*_*M H 17 android nine-patch android-custom-view android-intent
在我的应用程序中,我想将气泡设置为文本视图,在我添加的文本视图中setBackgroundResource(),您可以在代码中看到.
使用此代码我得到这样的图像:
我想要一个像这样的气泡形状图像:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#EDF5E4" />
<corners android:bottomLeftRadius="@dimen/corner_radius"
android:bottomRightRadius="@dimen/corner_radius"
android:topLeftRadius="@dimen/corner_radius"
id:topRightRadius="@dimen/corner_radius" />
Run Code Online (Sandbox Code Playgroud)
请告诉我如何在我的setBackgroundResource()XML中进行此操作.
Sid*_*ele 31
您需要使用的是一个9补丁图像(正如Ken Wolf在本评论中已经指出的那样).
为了帮助您入门,我在其中一个应用程序中包含了一组9补丁图像,以及在创建布局XMl时如何使用它的简短代码.;-)
9补丁图像集:

(这些被命名为:bubble_white_normal_mdpi.9,bubble_white_normal_hdpi.9并bubble_white_normal_xhdpi.9分别删除了_mdpi,_hdpi和_xhdpi将它们放置在各自后,从文件名drawable的文件夹.
XML:
<LinearLayout
android:id="@+id/linlaUserOther"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="2dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="top|center" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgvwProfileOther"
android:layout_width="42dp"
android:layout_height="42dp"
android:adjustViewBounds="true"
android:contentDescription="@string/content_desc_user_profile"
android:scaleType="centerCrop"
android:src="@drawable/ic_contact_picture" >
</ImageView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/bubble_white_normal"
android:gravity="top|center"
android:orientation="vertical" >
.... // OTHER STUFF HERE THAT IS NOT NECESSARY IN THIS CODE SNIPPET ON SO
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
注1:
虽然,我包括一组工作图像(几乎是勺子喂食,如果你愿意的话),我强烈建议你创建一套适合你的方案的图像.此外,这还将使您能够在将来构建自己的资源.我加倍努力的唯一原因是因为我个人失去了3天,让讲话泡泡看上去正常.:-(
笔记2:
我将图像设置为背景LinearLayout.但是,TextView您需要将其设置为您需要的语音泡泡.
其他网站(教程):
| 归档时间: |
|
| 查看次数: |
27012 次 |
| 最近记录: |