Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-消息传递应用程序布局_Android_Android Layout_Android Listview_Android Edittext - Fatal编程技术网

Android-消息传递应用程序布局

Android-消息传递应用程序布局,android,android-layout,android-listview,android-edittext,Android,Android Layout,Android Listview,Android Edittext,我正在尝试从股票Android消息应用程序复制布局。我使用一个列表视图完成了这项工作,该列表视图为对话提供了一个自定义适配器,为“发送消息”部分提供了一个固定的布局。它看起来像这样: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/container" android

我正在尝试从股票Android消息应用程序复制布局。我使用一个列表视图完成了这项工作,该列表视图为对话提供了一个自定义适配器,为“发送消息”部分提供了一个固定的布局。它看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp" >

<ListView
    android:id="@+id/listview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/sendMsgLayout"
    android:overScrollMode="always"
    android:stackFromBottom="true"
    android:layout_alignParentTop="true" >
</ListView>

<RelativeLayout
    android:id="@+id/sendMsgLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="5dp" >

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/list_divider" />

    <EditText
        android:id="@+id/messageText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_toLeftOf="@+id/imageSend"
        android:hint="@string/type_message"
        android:maxLines="3" >

        <requestFocus />
    </EditText>

    <ImageView
        android:id="@+id/imageSend"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/messageText"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        android:src="@drawable/send" />
</RelativeLayout>

这是我最新版本的布局,我还使用了LinearLayout作为父级,列表视图的权重设置为1

编辑文本最多有3行。当一行不够容纳文本且编辑文本增长时,就会出现问题。它涵盖了列表视图的一部分。 我认为每当编辑文本在维度上增长时,我应该滚动列表视图,但我无法实现这一点

关于如何解决这个问题有什么想法吗?

试试下面的代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:orientation="vertical" >

<ListView
    android:id="@+id/listview"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:stackFromBottom="true"
    android:layout_weight="1" >
</ListView>

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@color/list_divider" />

<LinearLayout
    android:id="@+id/sendMsgLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:layout_marginTop="20dp"
    android:orientation="horizontal" >

    <EditText
        android:id="@+id/messageText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_marginLeft="10dp"
        android:hint="@string/type_message"
        android:maxLines="3" >

        <requestFocus />
    </EditText>

    <ImageView
        android:id="@+id/imageSend"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        android:src="@drawable/send" />
</LinearLayout>

</LinearLayout>

试试这种方法,希望这能帮助您解决问题。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="2dp"
    android:orientation="vertical">

    <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:overScrollMode="always"
        android:stackFromBottom="true"
        android:layout_marginBottom="5dp"/>

    <LinearLayout
        android:id="@+id/sendMsgLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/messageText"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:hint="@string/type_message"
            android:maxLines="3" >

            <requestFocus />
        </EditText>

        <ImageView
            android:id="@+id/imageSend"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/send" />
    </LinearLayout>
</LinearLayout>

将listview转录模式设置为正常,交替始终滚动,正如@andreid remove android:overScrollMode=“always”所指出的那样

或在代码中:

listView.setTranscriptMode(AbsListView.TRANSCRIPT_MODE_NORMAL);

添加这两个属性android:singleLine=“true”,android:scrollbars=“vertical”,并删除这一个android:maxLines=“3”。您可以尝试将底部视图作为列表视图的页脚,而不是作为布局的单独部分。@Haresh他仍然想要3行,他只是不想让Brad Pitt在写3行时遮住脸。我没有太多使用ListView,但将ListView包装并在LinearLayout中发送MsgLayout难道不起作用吗?@Haresh我希望编辑文本有3行。@Rawa是的,那是我的错误。。。我在列表视图上留下了一些早期尝试的属性“overScrollMode”。这导致了不良的滚动效果。“android:transcriptMode”适用于普通和alwaysScroll。我会相应地更新我的帖子。你可以把它作为答案贴出来,这样我就可以接受它作为正确答案。谢谢!正如我在原始帖子中所说,我尝试了线性布局和权重设置为1的方法。。结果是一样的(我尝试了你的代码,同样的行为)。用android:TranscrollMode替换android:OvercrollMode解决了这个问题。
listView.setTranscriptMode(AbsListView.TRANSCRIPT_MODE_NORMAL);