Android布局:评论活动类似于Facebook应用

西蒙

我一直在看Facebook评论活动:

Facebook

我一直想知道他们如何设法使edittext的大小从一行增加到最多4行,同时,包含这些帖子的recyclerview也会向上调整并减小大小。当您输入文字时,这会自动发生。

我正在尝试通过执行以下操作自己复制其布局,但我不能显示多于2行。它一直将自身限制为“发送”箭头的大小,但在下面的示例中,edittext永远不会超过recyclerview。

我的脸书

以下是我的xml布局代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/white"
    >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/like_box"
        android:text="Number of Likes goes here"
        android:maxLines="1"
        android:minLines="1"
        android:layout_margin="16dp"
        />

    <View
        android:layout_width="match_parent"
        android:layout_height="0.2dp"
        android:id="@+id/divider"
        android:layout_below="@+id/like_box"
        android:background="@color/half_black"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_below="@+id/divider"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/commenttext" />

    <View
        android:layout_width="match_parent"
        android:layout_height="0.2dp"
        android:id="@+id/divider2"
        android:layout_below="@+id/my_recycler_view"
        android:background="@color/half_black"/>


        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/commenttext"
            android:layout_toLeftOf="@+id/send"
            android:background="@null"
            android:paddingLeft="16dp"
            android:textSize="16sp"
            android:hint="Add a comment here"
            android:layout_alignTop="@+id/send"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentBottom="true" />

        <ImageView
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:id="@+id/send"
            android:src="@drawable/ic_action_send_now"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />
</RelativeLayout>

Does anyone know what the correct xml layout code is to ensure that both the edittext and recyclerview adjust upwards when text is entered? I thought it would just be something simple like setting "wrap_content" to my edittext which I have already done but it still does not adjust properly.

Anoop M's answer seems to be the closest to what I want to do but the recyclerview does not adjust properly - see image below. Imagine if the blue portion of the screen was filled with text, the edittext will end up hiding the text in the blue section when you enter more than 4 lines. The edittext just seems to go over the recyclerview. This does not happen on the facebook app, comments are fully shown as the recyclerview adjust upwards when the edittext size increases.

Anoop M's answer

Vikram

我建议使用aLinearLayout作为父容器。然后,可以通过layout_weights在所有子视图上应用来获得所需的结果

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/like_box"
        android:text="Number of Likes goes here"
        android:maxLines="1"
        android:minLines="1"
        android:layout_margin="16dp"
        android:layout_weight="0"/>

    <View
        android:layout_width="match_parent"
        android:layout_height="0.2dp"
        android:id="@+id/divider"
        android:background="@color/half_black"
        android:layout_weight="0"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

    <View
        android:layout_width="match_parent"
        android:layout_height="0.2dp"
        android:id="@+id/divider2"
        android:background="@color/half_black"
        android:layout_weight="0"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:orientation="horizontal">

        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/commenttext"
            android:background="@null"
            android:paddingLeft="16dp"
            android:textSize="16sp"
            android:maxLines="4"
            android:inputType="textMultiLine"
            android:hint="Add a comment here" />

        <ImageView
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:id="@+id/send"
            android:src="="@drawable/ic_action_send_now"
            android:layout_weight="0" />

    </LinearLayout>

</LinearLayout>

显着变化:

  • 父容器现在 LinearLayout
  • 所有子视图均已layout_weights分配
  • EditTextsend按钮已被容纳在水平内LinearLayout
  • maxLines的属性EditText4根据您的要求设置。这样,EditText遗嘱的高度会不断增长,直到其4行高,然后开始滚动。send按钮将保持与第一行对齐。
  • inputType="textMultiLine"已添加到中,EditText以表明其内容EditText可以跨越多行。
  • RecyclerViewEditText's行数增加它将缩小,反之亦然。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Twitter评论功能类似于Facebook?

来自分类Dev

关于应用程序布局的TVOS(类似于iTunes等)

来自分类Dev

关于应用程序布局的TVOS(类似于iTunes等)

来自分类Dev

ios导航栏色调颜色(类似于facebook应用)

来自分类Dev

Android List视图布局类似于Google Play

来自分类Dev

如何更改类似于Android中的图像的相对布局形状

来自分类Dev

是否有可能创建一个最近用过显示类似于Android的我的应用程序的活动

来自分类Dev

ListView类似于Android中的Google Play设置活动

来自分类Dev

布局类似于 Appear.in

来自分类Dev

Android-如何在Facebook的应用程序中使内容具有内容块(类似于后块)

来自分类Dev

Laravel:行为类似于softdelete的活动列

来自分类Dev

如何获得类似于Facebook应用程序的MultiAutoCompleteTextView令牌生成器?

来自分类Dev

类似于TreeView Android的ExpandableListview

来自分类Dev

类似Facebook的评论刷新系统?

来自分类Dev

用express显示类似facebook的评论

来自分类Dev

类似Facebook的评论刷新系统?

来自分类Dev

Android Facebook Messenger键盘调整大小活动布局

来自分类Dev

添加类似于Facebook使用的效果

来自分类Dev

Swift中的滑动导航类似于Facebook

来自分类Dev

类似于StackExchange / Facebook的通知框定位

来自分类Dev

布局SwiftUI的正确方法(类似于自动布局)

来自分类Dev

如何在Android中正确实现Feed(类似于Facebook / Instagram)?

来自分类Dev

如何创建类似于instagram布局应用的手势驱动的动态可调整大小的视图

来自分类Dev

类似于 Oracle Forms 的应用程序

来自分类Dev

mysql搜索类似于在默认android联系人应用中进行搜索

来自分类Dev

mysql搜索类似于在默认android联系人应用中进行搜索

来自分类Dev

Xamarin Forms 中的应用程序设置/属性类似于 Android 中的共享首选项

来自分类Dev

类似于WhatsApp的多行EditText及其旁边的按钮的布局

来自分类Dev

CSS挑战:jQuery在特定的特定布局上类似于slideDown

Related 相关文章

  1. 1

    Twitter评论功能类似于Facebook?

  2. 2

    关于应用程序布局的TVOS(类似于iTunes等)

  3. 3

    关于应用程序布局的TVOS(类似于iTunes等)

  4. 4

    ios导航栏色调颜色(类似于facebook应用)

  5. 5

    Android List视图布局类似于Google Play

  6. 6

    如何更改类似于Android中的图像的相对布局形状

  7. 7

    是否有可能创建一个最近用过显示类似于Android的我的应用程序的活动

  8. 8

    ListView类似于Android中的Google Play设置活动

  9. 9

    布局类似于 Appear.in

  10. 10

    Android-如何在Facebook的应用程序中使内容具有内容块(类似于后块)

  11. 11

    Laravel:行为类似于softdelete的活动列

  12. 12

    如何获得类似于Facebook应用程序的MultiAutoCompleteTextView令牌生成器?

  13. 13

    类似于TreeView Android的ExpandableListview

  14. 14

    类似Facebook的评论刷新系统?

  15. 15

    用express显示类似facebook的评论

  16. 16

    类似Facebook的评论刷新系统?

  17. 17

    Android Facebook Messenger键盘调整大小活动布局

  18. 18

    添加类似于Facebook使用的效果

  19. 19

    Swift中的滑动导航类似于Facebook

  20. 20

    类似于StackExchange / Facebook的通知框定位

  21. 21

    布局SwiftUI的正确方法(类似于自动布局)

  22. 22

    如何在Android中正确实现Feed(类似于Facebook / Instagram)?

  23. 23

    如何创建类似于instagram布局应用的手势驱动的动态可调整大小的视图

  24. 24

    类似于 Oracle Forms 的应用程序

  25. 25

    mysql搜索类似于在默认android联系人应用中进行搜索

  26. 26

    mysql搜索类似于在默认android联系人应用中进行搜索

  27. 27

    Xamarin Forms 中的应用程序设置/属性类似于 Android 中的共享首选项

  28. 28

    类似于WhatsApp的多行EditText及其旁边的按钮的布局

  29. 29

    CSS挑战:jQuery在特定的特定布局上类似于slideDown

热门标签

归档