Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.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
Java 在资源文件中包装内容,其行为类似于匹配父项_Java_Android_Android Layout - Fatal编程技术网

Java 在资源文件中包装内容,其行为类似于匹配父项

Java 在资源文件中包装内容,其行为类似于匹配父项,java,android,android-layout,Java,Android,Android Layout,截图- - 正如你所看到的,这是一个回收视图,应该是包装内容,但有些行为不同。。。我没有任何关于这是如何发生的或应该发生的解释。。。也许有人能帮我 代码 在添加新规则之前,请尝试删除规则 正如我们在屏幕截图中看到的,左侧的两条消息(ok和ufff)完美地显示出来 参数移除规则(相对长度对齐左); 参数移除规则(相对长度对齐\u父项\u右) 完成@MikeM…。你的问题回收视图是否位于appbar后面,而它应该在appbar下面?appbar下面没有回收视图这很好。。。但是当文本视图包装内容时,它

截图- -

正如你所看到的,这是一个回收视图,应该是包装内容,但有些行为不同。。。我没有任何关于这是如何发生的或应该发生的解释。。。也许有人能帮我

代码


在添加新规则之前,请尝试删除规则

正如我们在屏幕截图中看到的,左侧的两条消息(ok和ufff)完美地显示出来

参数移除规则(相对长度对齐左); 参数移除规则(相对长度对齐\u父项\u右)


完成@MikeM…。你的问题回收视图是否位于appbar后面,而它应该在appbar下面?appbar下面没有回收视图这很好。。。但是当文本视图包装内容时,它有时就像匹配父对象一样
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">


<android.support.design.widget.AppBarLayout
    android:id="@+id/actionBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/black">

        <RelativeLayout
            android:padding="2dp"
            android:layout_width="wrap_content"
            android:layout_height="match_parent">

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


                <TextView
                    android:text="Name"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="5dp"
                    android:id="@+id/name"
                    android:textColor="@color/white"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="20dp"/>

                <TextView
                    android:text="Online"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="5dp"
                    android:id="@+id/online"
                    android:textColor="@color/white"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="15dp"/>

            </LinearLayout>

            <ImageButton
                android:layout_centerVertical="true"
                android:background="@null"
                android:src="@drawable/search"
                android:layout_alignParentRight="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />


        </RelativeLayout>
    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>

<android.support.v7.widget.RecyclerView
    android:layout_above="@+id/linearlayout"
    android:scrollbars="vertical"
    android:id="@+id/message_list"
    android:layout_below="@+id/actionBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>


<RelativeLayout
    android:padding="1dp"
    android:layout_alignParentBottom="true"
    android:id="@+id/linearlayout"
    android:layout_width="match_parent"
    android:layout_height="50dp">


<ImageButton
    android:src="@drawable/add_image"
    android:id="@+id/add_image"
    android:layout_width="50dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true" />

<EditText
    android:textColorHint="@color/black"
    android:hint="Write a message..."
    android:id="@+id/input_message"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toEndOf="@+id/add_image"
    android:layout_toStartOf="@+id/send_message" />

    <ImageButton
        android:src="@drawable/send_button"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:id="@+id/send_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Send" />

</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/message_single_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp">

<TextView
    android:id="@+id/message_text_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="@drawable/text_background2"
    android:padding="10dp"
    android:text="Textview"
    android:textSize="15dp"
    android:textColor="@color/black"/>

</RelativeLayout>
if (from_user != null && from_user.equals(current_user_id)) {
        holder.messageText.setTextColor(Color.BLACK);


        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.messageText.getLayoutParams();
        params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        holder.messageText.setLayoutParams(params);

                if (Seen==1){
                    holder.messageText.setBackgroundResource(R.drawable.text_background2);
                }else{
                    holder.messageText.setBackgroundResource(R.drawable.text_background1);
                }

    }else {
            holder.messageText.setBackgroundResource(R.drawable.text_background2);
            holder.messageText.setTextColor(Color.BLACK);

        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.messageText.getLayoutParams();
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        holder.messageText.setLayoutParams(params);
        }

        holder.messageText.setText(messages.getMessage());
    }
if (from_user != null && from_user.equals(current_user_id)) {
    holder.messageText.setTextColor(Color.BLACK);
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.messageText.getLayoutParams();
    //remove rules
    params.removeRule(RelativeLayout.ALIGN_PARENT_LEFT);

    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    holder.messageText.setLayoutParams(params);

            if (Seen==1){
                holder.messageText.setBackgroundResource(R.drawable.text_background2);
            }else{
                holder.messageText.setBackgroundResource(R.drawable.text_background1);
            }

}else {
        holder.messageText.setBackgroundResource(R.drawable.text_background2);
        holder.messageText.setTextColor(Color.BLACK);

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.messageText.getLayoutParams();
    //remove rules
    params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT);

    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    holder.messageText.setLayoutParams(params);
    }

    holder.messageText.setText(messages.getMessage());
}