前言
在实际的开发当中,我们会使用<include>标签进行布局重用,降低减少布局的层次,是我们布局优化的手段之一。我遇到了一个情况,使用<include>标签之后,界面的其他布局控件居然无法显示了。
问题重现
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical">
<include layout="@layout/view_title"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/page_background"
android:orientation="vertical">
<RelativeLayout
android:layout_width="@dimen/px_size_2"
android:layout_height="@dimen/dp_size_27"
android:layout_marginLeft="@dimen/dp_size_20"
android:background="@color/message_line"
tools:ignore="RtlHardcoded" />
<android.support.v7.widget.RecyclerView
android:id="@+id/message_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
界面的效果是这样的

解决办法
<include layout="@layout/view_title"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_size_69"/>
加入宽度和高度的属性之后就解决了,希望这篇文章对Android开发的小伙伴有用。
本文介绍了一个使用<include>标签导致的界面布局显示问题,并给出了解决方案。通过为<include>标签设置宽度和高度属性,可以避免其他布局控件无法正常显示的问题。
2738

被折叠的 条评论
为什么被折叠?



