【问题标题】:Android layout like Messaging appAndroid 布局,如消息应用程序
【发布时间】:2015-02-26 01:55:39
【问题描述】:

我正在尝试创建一个类似于现有 Android 消息传递应用程序使用的 Android GUI。

  • EditText 和 Button 将被锚定到视图的底部。 EditText 可以放大和缩小以显示一行或多行文本。 Button 将放置在 EditText 的右侧。
  • MvvmCross MvxListView 将填充剩余空间。 MvxListView 应该随着 EditText 的缩小和增长,或者键盘被用户弹出来自动垂直调整大小。

我无法想出完全符合我要求的东西。我当前解决方案的问题是硬编码的边距。当我输入两行文本时,我最终会看到重叠的视图。有谁知道如何让 MvxListView 增长/缩小以填充剩余空间?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Mvx.MvxListView
        android:id="@+id/MessageConversationView_MessageList"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:dividerHeight="2dp"
        android:divider="@null"
        android:stackFromBottom="true"
        android:transcriptMode="alwaysScroll"
        android:layout_marginBottom="50dp"
        local:MvxBind="ItemsSource Messages" />
    <RelativeLayout
        android:id="@+id/InnerRelativeLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
        <Button
            android:text="Send"
            android:id="@+id/Button"
            android:layout_alignParentRight="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <EditText
            android:id="@+id/EditText"
            android:layout_width="fill_parent"
            android:layout_toLeftOf="@id/Button"
            android:layout_height="wrap_content" />
    </RelativeLayout>
</RelativeLayout>

【问题讨论】:

  • 什么是Mvx.MvxListView
  • 我正在使用 C#、MvvmCross 和 Xamarin.Android。 Mvx.MvxListView 是一个 MvvmCross ListView 控件。 MvvmCross 是一个 C# MVVM 库,适用于 Android、iOS、Windows Phone 等。

标签: android android-layout xamarin


【解决方案1】:

如果我对您的理解正确,您会喜欢下面的内容。注意:我使用 Android Studio 和常规 ListView 编写了此代码,即它没有针对 Xamarin 进行测试。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

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

        <Button

            android:text="Send"
            android:id="@+id/Button"
            android:layout_alignParentRight="true"

            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <EditText
            android:id="@+id/EditText"
            android:layout_width="fill_parent"
            android:layout_toLeftOf="@id/Button"
            android:layout_height="wrap_content" />
    </RelativeLayout>

    <Mvx.MvxListView
        android:layout_above="@+id/InnerRelativeLayout"
        android:id="@+id/MessageConversationView_MessageList"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:dividerHeight="2dp"
        android:divider="@null"
        android:stackFromBottom="true"
        android:transcriptMode="alwaysScroll"
        local:MvxBind="ItemsSource Messages" />

</RelativeLayout>

填充列表的结果:

用户输入文本时的结果:

这也适用于 Xamarin。

【讨论】:

  • 是的,我想你明白我在找什么。但是,Xamarin 无法加载该布局,因为它有多个根元素。
  • 是的,那是我的错,我忘了正确格式化它。现在试试 :-) @TrevorBalcom
  • 它正在工作。我看到你的布局和我的布局之间的主要区别是第二个 RelativeLayout 的嵌套,并将 layout_above 添加到 ListView。
  • 正确 :-) 编码愉快! @TrevorBalcom
猜你喜欢
  • 1970-01-01
  • 2011-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多