我使用一个LinearLayout为了有一个行为像聊天界面的UI(这意味着,在底部,我有一个多行EditText和一个按钮(发送消息),并在它之上,一个显示消息的列表视图)。一个聊天界面的布局
ListView应该占用EditText和Button留下的空闲空间。
现在,我有一个垂直LinearLayout,其中包含一个FrameLayout(其中包含ListViewes,我只同时显示一个ListView)和一个RelativeLayout(其中包含EditText和Button)。 我已经把重量放在我的FrameLayout和我的RelativeLayout上,以确保Listview几乎占据了所有的空间。
现在,它的工作原理,但问题是,当我集中EditText(为了输入它),EditText变得非常小(它只显示一行)。
但是我想在它没有聚焦的时候有一个小的EditText(为了在列表视图中显示尽可能多的消息)和一个更大的EditText(当我打字的时候显示尽可能多的行) 。
这里是我的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="1dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:paddingTop="1dp"
tools:context=".ChatActivity"
android:background="#f0f4fc"
android:weightSum="100">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="82" >
<ListView
android:id="@+id/chat1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
/>
<ListView
android:id="@+id/chat2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
android:visibility="gone" />
</FrameLayout>
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="18"
android:background="#f0f4fc"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
<EditText
android:id="@+id/messageBox"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/sendButton"
android:ems="10"
android:gravity="top"
android:hint="@string/enterMessageHere"
android:minHeight="50dp"
android:inputType="textMultiLine"
android:lines="3"
android:maxLines="3"
android:minLines="3" >
<!-- <requestFocus /> -->
</EditText>
<Button
android:id="@+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="@string/send" />
</RelativeLayout>
因此,概括地说,我希望有类似的“GO短信”界面,这将是巨大的。
在此先感谢您的帮助!
看看是否有帮助:[ListView中的左右对齐行?](http://stackoverflow.com/questions/17762473/left-and-right-alignment-rows-inside-listview/17762749#17762749) – Vikram