我是新來的android和我正在開發一個應用程序相關的在線聊天。在聊天屏幕中,我試圖將聊天框大小設置爲文本視圖大小。如何設置相對佈局大小隨着texview尺寸increese增加
隨着文本視圖大小的增加和減少,如何增加和減少聊天框大小?
我是新來的android和我正在開發一個應用程序相關的在線聊天。在聊天屏幕中,我試圖將聊天框大小設置爲文本視圖大小。如何設置相對佈局大小隨着texview尺寸increese增加
隨着文本視圖大小的增加和減少,如何增加和減少聊天框大小?
設置Relative Layout
高度爲wrap_content
以及textview
高度。
WRAP_CONTENT
,這意味着該視圖要足夠大以包含其內容。
我知道包裝內容。但我不能用這種情況,因爲我需要一些固定的初始尺寸 – user1684892
看到這個
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:weightSum="1.0"
android:layout_weight="1" android:layout_height="wrap_content">
<TextView android:id="@+id/lefttext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:layout_marginBottom="5dip"
android:layout_alignParentLeft="true"
android:maxWidth="250dip"/>
<TextView
android:id="@+id/righttext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:layout_marginBottom="5dip"
android:layout_alignParentRight="true"
android:maxWidth="250dip"/>
</RelativeLayout>
這是我的自定義陣列適配器的getView方法中的代碼:
View view = convertView;
if(view == null){
view = mInflater.inflate(R.layout.list_item, null);
}
Resources res = getContext().getResources();
Drawable bubblesChat = res.getDrawable(R.drawable.bubbles_chat);
Drawable bubblesResponse = res.getDrawable(R.drawable.bubbles_response);
TextView left = (TextView) view.findViewById(R.id.lefttext);
TextView right = (TextView) view.findViewById(R.id.righttext);
String txt = super.getItem(position);
if(txt.startsWith("s:")) {
left.setText(getItem(position));
left.setBackgroundDrawable(bubblesChat);
right.setText("");
right.setBackgroundDrawable(null);
} else {
right.setText(getItem(position));
right.setBackgroundDrawable(bubblesResponse);
left.setText("");
left.setBackgroundDrawable(null);
}
return view;
Alternate chat bubble widths 和http://warting.se/2012/06/04/chat-bubbles-in-android/
你可以把佈局最好是RelativeLayout
並且每當您的TextView
大小增加或減少刷新您的聊天動態設置新的LayoutParams
來查看。
使用9patch圖像它會自動執行。 –
使用draw9補丁作爲佈局背景,但使用9補丁後的問題是我無法在該佈局內添加任何內容。當我插入類似圖像和文本視圖時,它會超出該佈局。 – user1684892
你能告訴你如何嘗試。分享你的9patch圖像。 –