Android 9补丁图像的奇怪行为
我正在开发一个聊天应用程序,我正在使用9补丁泡泡 用于在屏幕上显示气泡的功能Android 9补丁图像的奇怪行为,android,nine-patch,Android,Nine Patch,我正在开发一个聊天应用程序,我正在使用9补丁泡泡 用于在屏幕上显示气泡的功能 static void showMessage(String message, boolean leftSide) { Log.d("abc","show"); final TextView textView = new TextView(activity); textView.setTextColor(Color.BLACK); textVi
static void showMessage(String message, boolean leftSide)
{
Log.d("abc","show");
final TextView textView = new TextView(activity);
textView.setTextColor(Color.BLACK);
textView.setText(message);
int bgRes = R.drawable.left_message_bg;
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
if (!leftSide)
{
bgRes = R.drawable.right_message_bg;
params.gravity = Gravity.RIGHT;
}
textView.setLayoutParams(params);
textView.setBackgroundResource(bgRes);
messagesContainer.addView(textView);
// Scroll to bottom
if (scrollContainer.getChildAt(0) != null)
{
scrollContainer.scrollTo(scrollContainer.getScrollX(), scrollContainer.getChildAt(0).getHeight());
}
scrollContainer.fullScroll(View.FOCUS_DOWN);
}
XML布局
<?xml version="1.0" encoding="utf-8"?>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/messageEdit"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:autoText="true"
android:hint="message text"
android:layout_alignParentRight="false"
android:layout_toLeftOf="@+id/sendButton"
android:layout_marginRight="10dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:id="@+id/sendButton"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
<ScrollView
android:id="@+id/scrollContainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:layout_marginBottom="20dp" android:layout_above="@+id/messageEdit"
android:layout_below="@+id/meLabel" android:layout_marginTop="10dp">
<LinearLayout
android:id="@+id/messagesContainer"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
</ScrollView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/headerforchat"
android:text="Me"
android:id="@+id/meLabel" android:layout_gravity="left|center_vertical" android:singleLine="false"
android:textSize="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/headerforchat"
android:text="Friend"
android:id="@+id/friendLabel" android:layout_alignParentRight="true" android:textSize="20dp"/>
</RelativeLayout>
9个补丁图像
任何帮助都将不胜感激我猜您只将9-patch放在了一个可绘制文件夹(
可绘制xhdpi
)中。当放置在非xhdpi的设备上时,它会缩小(包括定义的外部黑色像素),并且不再能够解释为9面片,因此它会失败。或者制作一个缩放的mdpi和hdpi版本,或者将其放置在可绘制的nodpi
我已经将它们放置在所有不同密度的文件夹中。那么,你能发布有问题的9-patch吗?嗯,我真的不确定。我的一个意见是,你只需要在顶部和左侧的一个像素,但它不会打破你现在拥有的方式。这似乎是一个衡量问题。你不使用ListView和适配器是有原因的吗?我还尝试过交换图像,表示蓝色气泡用于显示发送消息,橙色气泡用于显示接收到的消息。现在它正确显示蓝色气泡,但有线橙色气泡。显示接收到的msgHmm的唯一问题是没有真正的理由不使用列表视图。它能解决问题吗??
left_message_bg-->The orange bubble which will display after sending message
right_message_bg-->The blue bubble which will display after receiving message