2012-09-24 46 views
0

我是新來的android和我正在開發一個應用程序相關的在線聊天。在聊天屏幕中,我試圖將聊天框大小設置爲文本視圖大小。如何設置相對佈局大小隨着texview尺寸increese增加

隨着文本視圖大小的增加和減少,如何增加和減少聊天框大小?

+0

使用9patch圖像它會自動執行。 –

+0

使用draw9補丁作爲佈局背景,但使用9補丁後的問題是我無法在該佈局內添加任何內容。當我插入類似圖像和文本視圖時,它會超出該佈局。 – user1684892

+0

你能告訴你如何嘗試。分享你的9patch圖像。 –

回答

1

設置Relative Layout高度爲wrap_content以及textview高度。

WRAP_CONTENT,這意味着該視圖要足夠大以包含其內容。

+0

我知道包裝內容。但我不能用這種情況,因爲我需要一些固定的初始尺寸 – user1684892

1

看到這個

<?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 widthshttp://warting.se/2012/06/04/chat-bubbles-in-android/

0

你可以把佈局最好是RelativeLayout並且每當您的TextView大小增加或減少刷新您的聊天動態設置新的LayoutParams來查看。

相關問題