首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >相对布局放置到其他相对布局

相对布局放置到其他相对布局
EN

Stack Overflow用户
提问于 2014-10-02 10:04:11
回答 7查看 71关注 0票数 1

我正在开发一个聊天应用程序,我想把编辑文本放在底部,然后把消息放在it.But之上,我有一个问题:

我不想把消息放在编辑文本的顶部,button.How我能阻止这种情况吗?这是我的xml:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ECECFB"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/message_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"/>

 <RelativeLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >


           <EditText
        android:id="@+id/message"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" /> 

               <Button
        android:id="@+id/get_from_user"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:text="Gönder" />
    </RelativeLayout>

</RelativeLayout>

我还有一个question.How,我可以像其他聊天应用程序一样做消息列表系统吗?我的意思是,当我将这个消息发送到列表的底部,而不是我的xml中的top.Now时,它会把这个消息放在top.Like上:

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2014-10-02 10:11:27

ListView设置在EditText布局之上。您的布局如下:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ECECFB">

 <RelativeLayout 
        android:id="@+id/bottom_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >


        <EditText
        android:id="@+id/message"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" /> 

        <Button
        android:id="@+id/get_from_user"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:text="Gönder" />
    </RelativeLayout>

     <ListView
        android:id="@+id/message_list"
        android:layout_above="@id/bottom_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

至于你的第二个问题,

代码语言:javascript
运行
复制
android:stackFromBottom="true"
android:transcriptMode="normal"

ListView

票数 1
EN

Stack Overflow用户

发布于 2014-10-02 10:08:36

第一个问题:您需要设置RelativeLayout

代码语言:javascript
运行
复制
android:bellow="@+id/message_list"

2问题:您需要设置ListView:

代码语言:javascript
运行
复制
android:stackFromBottom="true"
android:transcriptMode="normal"

最后的Xml:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ECECFB"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/message_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:stackFromBottom="true"
        android:transcriptMode="normal"/>

 <RelativeLayout
        android:bellow="@+id/message_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >


           <EditText
        android:id="@+id/message"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" /> 

               <Button
        android:id="@+id/get_from_user"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:text="Gönder" />
    </RelativeLayout>

</RelativeLayout>
票数 1
EN

Stack Overflow用户

发布于 2014-10-02 10:08:54

例如,添加

代码语言:javascript
运行
复制
android:layout_below="@id/message_list"

对您的内部RelativeLayout进行约束,以约束ListView和底部RelativeLayout之间的关系,而不是将它们放置在对方的上面。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26158566

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档