【问题标题】:My include layout in coordinate layout overlapping with another layout我在坐标布局中的包含布局与另一个布局重叠
【发布时间】:2016-03-15 13:32:13
【问题描述】:

我正在处理带有嵌套滚动视图的协调器布局。我的布局中屏幕底部还有 3 个按钮。现在,当我滚动布局时,滚动视图的最后一个元素与我放在底部的按钮重叠。我尝试使用相对布局作为父级来摆脱这个问题,但它仍然存在。那么我怎样才能摆脱这个问题呢?下面给出了布局:

activity_agent_profile_2:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
tools:context=".AgentProfileActivity2">

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    android:fitsSystemWindows="true"
    android:layout_above="@+id/laytbtns">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="270dp"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/agent_profile_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginBottom="125dp"
            app:expandedTitleMarginStart="118dp"
            app:expandedTitleTextAppearance="@style/expandedappbar"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#fff"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax">

                <ImageView
                    android:id="@+id/backdrop"
                    android:layout_width="match_parent"
                    android:layout_height="180dp"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    android:src="@drawable/back" />

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="180dp"
                    android:background="#66000000">

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

                        <TextView
                            android:id="@+id/lbl_agent_profile_position"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/lbl_agent_profile_Name"
                            android:ellipsize="end"
                            android:maxLines="1"
                            android:text="Real Estate Professional at Exit Alliance Realty"
                            android:textAppearance="?android:attr/textAppearanceSmall"
                            android:textColor="#fff"
                            android:textSize="12sp"
                            android:typeface="sans" />

                        <TextView
                            android:id="@+id/lbl_agent_profile_membersince"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Member Since: 2015"
                            android:textAppearance="?android:attr/textAppearanceSmall"
                            android:textColor="#fff"
                            android:textSize="13sp"
                            android:typeface="sans" />
                    </LinearLayout>
                </RelativeLayout>

                <ImageView
                    android:id="@+id/img_agent_profile_image"
                    android:layout_width="100dp"
                    android:layout_height="140dp"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_marginLeft="12dp"
                    android:layout_marginStart="12dp"
                    android:scaleType="fitStart"
                    android:src="@drawable/no_profile" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/backdrop"
                    android:layout_marginLeft="5dp"
                    android:layout_toEndOf="@+id/img_agent_profile_image"
                    android:layout_toRightOf="@+id/img_agent_profile_image"
                    android:orientation="vertical">

                    <RelativeLayout
                        android:id="@+id/relativeLayout3"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#fff">


                        <ImageView
                            android:id="@+id/imageView13"
                            android:layout_width="15dp"
                            android:layout_height="15dp"
                            android:layout_alignParentLeft="true"
                            android:layout_alignParentStart="true"
                            android:layout_centerVertical="true"
                            android:src="@drawable/ic_phone_img" />

                        <TextView
                            android:id="@+id/lbl_agent_profile_phone"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerVertical="true"
                            android:layout_marginLeft="3dp"
                            android:layout_toEndOf="@+id/imageView13"
                            android:layout_toRightOf="@+id/imageView13"
                            android:text="01723735134"
                            android:textAppearance="?android:attr/textAppearanceSmall"
                            android:textColor="#56698F"
                            android:textSize="13sp"
                            android:typeface="sans" />
                    </RelativeLayout>

                    <RelativeLayout
                        android:id="@+id/relativeLayout4"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#fff">


                        <ImageView
                            android:id="@+id/imageView14"
                            android:layout_width="15dp"
                            android:layout_height="15dp"
                            android:layout_alignParentLeft="true"
                            android:layout_alignParentStart="true"
                            android:layout_centerVertical="true"
                            android:src="@drawable/ic_location_nopadding" />

                        <TextView
                            android:id="@+id/lbl_agent_profile_address"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerVertical="true"
                            android:layout_marginLeft="3dp"
                            android:layout_toEndOf="@+id/imageView14"
                            android:layout_toRightOf="@+id/imageView14"
                            android:ellipsize="end"
                            android:maxLines="1"
                            android:text="2868 Al Urabuh Road, Al Urudh, Ryadh"
                            android:textAppearance="?android:attr/textAppearanceSmall"
                            android:textColor="#56698F"
                            android:textSize="12sp"
                            android:typeface="sans" />
                    </RelativeLayout>

                    <RelativeLayout
                        android:id="@+id/relativeLayout5"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#fff">


                        <ImageView
                            android:id="@+id/imageView15"
                            android:layout_width="15dp"
                            android:layout_height="15dp"
                            android:layout_alignParentLeft="true"
                            android:layout_alignParentStart="true"
                            android:layout_centerVertical="true"
                            android:src="@drawable/ic_website" />

                        <TextView
                            android:id="@+id/lbl_agent_profile_website"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerVertical="true"
                            android:layout_marginLeft="3dp"
                            android:layout_toEndOf="@+id/imageView15"
                            android:layout_toRightOf="@+id/imageView15"
                            android:ellipsize="end"
                            android:maxLines="1"
                            android:text="www.ibaax.com"
                            android:textAppearance="?android:attr/textAppearanceSmall"
                            android:textColor="#56698F"
                            android:textSize="12sp"
                            android:typeface="sans" />
                    </RelativeLayout>
                </LinearLayout>
            </RelativeLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_marginTop="-50dp"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

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


    <include layout="@layout/content_agent_profile" />

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


<LinearLayout
    android:id="@+id/laytbtns"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_alignParentBottom="true"
    android:background="#495B81">

    <Button
        android:id="@+id/testbutton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginRight="1dp"
        android:layout_weight="1"
        android:background="#56688f"
        android:onClick="btnEmail_click"
        android:text="Message"
        android:textColor="#fff"
        android:textStyle="bold"
        android:typeface="sans" />

    <Button
        android:id="@+id/SMSButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginRight="1dp"
        android:layout_weight="1"
        android:background="#56688f"
        android:onClick="btnSMS_click"
        android:text="SMS"
        android:textColor="#fff"
        android:textStyle="bold"
        android:typeface="sans" />

    <Button
        android:id="@+id/cancelButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#56688f"
        android:onClick="btnPhone_click"
        android:text="Call"
        android:textColor="#fff"
        android:textStyle="bold"
        android:typeface="sans" />

</LinearLayout></RelativeLayout>

content_agent_profile.xml:

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".AgentProfileActivity2"
tools:showIn="@layout/activity_agent_profile2">

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

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginTop="5dp"
        android:background="#d3d3d3" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:text="Specialities"
            android:textColor="#60aaff"
            android:textSize="18sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/lbl_agent_profile_specialites"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp" />

    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginTop="5dp"
        android:background="#d3d3d3" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:text="Service Area"
            android:textColor="#60aaff"
            android:textSize="18sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/lbl_agent_profile_service"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp" />

    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginTop="5dp"
        android:background="#d3d3d3" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:text="Profile Summery "
            android:textColor="#60aaff"
            android:textSize="18sp"
            android:textStyle="bold" />

        <WebView
            android:id="@+id/web_agentprofile_description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginTop="5dp"
        android:background="#d3d3d3" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:text="Active Listing"
            android:textColor="#60aaff"
            android:textSize="18sp"
            android:textStyle="bold" />

        <UI.ExpandableHeightGridView
            android:id="@+id/gridview_agent_property"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:horizontalSpacing="2dp"
            android:isScrollContainer="false"
            android:numColumns="1"
            android:stretchMode="columnWidth"
            android:verticalSpacing="2dp" />
    </LinearLayout>
</LinearLayout></android.support.v4.widget.NestedScrollView>

这是问题的图片: Contents in scroll view is being overlapped

编辑:

所以我通过在嵌套滚动视图中将 margin-bottom 设置为 80dp 来解决此问题。它现在似乎有效,但它不是一个永久的解决方案。如果有人能提出更好的解决方案,我将不胜感激。

【问题讨论】:

    标签: android android-layout material-design


    【解决方案1】:
    <include layout="@layout/content_agent_profile"
     android:layout_above="@+id/your above layout id"
        android:layout_below="@+id/below layout id"/>
    

    【讨论】:

    • 我的包含布局在协调器布局内。因此相对布局的 layout_above 或 layout_below/ 属性在坐标布局中不起作用。
    【解决方案2】:

    所以我通过在嵌套滚动视图中将 margin-bottom 设置为 80dp 来解决此问题。它现在似乎有效,但它不是一个永久的解决方案。如果有人能提出更好的解决方案,我将不胜感激。

    【讨论】:

      【解决方案3】:

      如果您使用 ConstraintLayout 并且您包含的布局与其他视图重叠,那么请提供您的包含布局高度和宽度。

      <include
                  android:id="@+id/errorScreen"
                  layout="@layout/error_screen_layout"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  app:layout_constraintEnd_toEndOf="parent"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintTop_toBottomOf="@+id/topView"/>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-23
        • 2011-06-15
        • 2011-08-03
        • 1970-01-01
        • 1970-01-01
        • 2020-02-29
        相关资源
        最近更新 更多