像FB Messenger一样的Android布局

时间:2015-01-18 19:15:55

标签: android android-layout

我希望布局类似于Facebook Messenger,底部的EditView和Button总是在底部,主要部分是可滚动的。

应该怎么样? 我写了类似的东西:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Send"
    android:id="@+id/button"/>

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText"
        android:layout_toLeftOf="@+id/button"
        android:layout_toStartOf="@+id/button"
        android:hint="write here.." />

</ScrollView>


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/textView"/>


</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

使用以下布局,您可以使用标题&amp;具有可滚动内容的页脚:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/top_control_bar">

        <Spinner
            android:id="@+id/sort_by"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

    </RelativeLayout>

    <LinearLayout
        android:id="@+id/bottom_control_bar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Add Item" />
    </LinearLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:choiceMode="multipleChoice"
        android:layout_below="@id/top_control_bar"
        android:layout_above="@id/bottom_control_bar"></ListView>

    <TextView
        android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/top_control_bar"
        android:layout_above="@id/bottom_control_bar" />

</RelativeLayout>

来源:http://blog.maxaller.name/2010/05/attaching-a-sticky-headerfooter-to-an-android-listview/

要实现类似于Facebook Messenger的聊天布局,请查看以下内容:

http://warting.se/2012/06/04/chat-bubbles-in-android/

http://warting.github.io/AndroidChatBubbles/

相关问题