Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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 像Instagram上的评论布局_Android - Fatal编程技术网

Android 像Instagram上的评论布局

Android 像Instagram上的评论布局,android,Android,我想在Instagram上做同样的行为,比如评论布局。因此,我添加了以下布局: <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="@dimen/persistent_buttons_area_height" andro

我想在Instagram上做同样的行为,比如评论布局。因此,我添加了以下布局:

       <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="@dimen/persistent_buttons_area_height"
            android:orientation="horizontal">

            <com.xxx.ui.widget.mention.AuthorMentionsEditText
                android:id="@+id/comment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="@dimen/keyline_1"
                android:paddingTop="@dimen/keyline_1"
                android:paddingLeft="@dimen/keyline_1"
                style="@style/ItemNewsFeedEditCommentMessage"
                android:layout_toLeftOf="@+id/send"
                android:inputType="text|textMultiLine|textCapSentences"
                android:scrollbars="vertical"
                android:hint="@string/news_feed_add_comment_hint" />

            <FrameLayout
                android:id="@+id/send"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:background="@color/theme_accent_3"
                android:layout_marginLeft="@dimen/keyline_7"
                android:padding="12dp">

                <com.xxx.ui.widget.IconView
                    android:id="@+id/send_icon"
                    android:layout_width="@dimen/keyline_4"
                    android:layout_height="@dimen/keyline_4"
                    app:iconFillColor="@color/text_2_secondary_color"
                    android:src="@drawable/ic_check" />

            </FrameLayout>

        </RelativeLayout>

结果是:

蓝色区域与其父区域不匹配。正常情况下,我在“发送”布局上设置“包裹内容”约束。因此,如果我通过“match_parent”进行更改,这就是直接的行为(没有文本!):


那么,像Instagram这样的蓝色区域(“发送”布局)我该怎么办呢?

添加“将发送按钮顶部和基线与注释框对齐”,这样它将填充整个大小

<FrameLayout
    android:id="@+id/send"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignBaseline="@id/comment" //<---
    android:layout_alignTop="@id/comment"      // <----
    android:background="@color/theme_accent_3"
    android:layout_marginLeft="@dimen/keyline_7"
    android:padding="12dp">

<com.xxx.ui.widget.IconView
    android:id="@+id/send_icon"
    android:layout_width="@dimen/keyline_4"
    android:layout_height="@dimen/keyline_4"
    app:iconFillColor="@color/text_2_secondary_color"
    android:src="@drawable/ic_check" />

</FrameLayout>
试试这个

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal">

    <EditText
        android:id="@+id/comment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:inputType="text|textMultiLine|textCapSentences"
        android:scrollbars="vertical" />


    <ImageView
        android:id="@+id/send_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:src="@drawable/ic_launcher_round" />


</LinearLayout>
输出

  • 正常

  • 当文本过长时

  • 更长的文本

这是布局的屏幕截图



您可以在XML中使用此布局来创建类似Instagram的此类布局。

无需使用外部库

只需在代码段上方复制粘贴即可:如您所需行instagram注释框

<?xml version="1.0" encoding="utf-8"?>
<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="com.example.user31.demosforstack.CommentInstagram">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">

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

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#00000000"
                android:gravity="start"
                android:hint="comment"
                android:padding="10dp" />

            <LinearLayout
                android:layout_width="50dp"
                android:layout_height="match_parent"
                android:background="#2698f8"
                android:gravity="center">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@drawable/ic_right_mark" />


            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

</RelativeLayout>

输出

简单无需添加任何文本

添加一些文本行后

添加许多行

希望对您有所帮助:)

<RelativeLayout
        android:id="@+id/commentAddLay"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_alignParentBottom="true">

        <EditText
            android:id="@+id/addcomment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_toLeftOf="@+id/send"
            android:background="@android:color/transparent"
            android:gravity="start"
            android:maxLines="4"
            android:padding="@dimen/dp_3"
            android:textSize="14sp"/>

        <ImageView
            android:id="@+id/send"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:background="#4E8CF5"
            android:padding="@dimen/dp_20"
            android:src="@mipmap/tick"/>

</RelativeLayout>  
<?xml version="1.0" encoding="utf-8"?>
<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="com.example.user31.demosforstack.CommentInstagram">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">

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

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#00000000"
                android:gravity="start"
                android:hint="comment"
                android:padding="10dp" />

            <LinearLayout
                android:layout_width="50dp"
                android:layout_height="match_parent"
                android:background="#2698f8"
                android:gravity="center">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@drawable/ic_right_mark" />


            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

</RelativeLayout>