如何在CoordinatorLayout中的AppBarLayout下面制作ViewStub

时间:2018-07-10 03:37:18

标签: android android-layout viewstub

我试图基于以下内容使用CoordinatorLayout创建我的个人资料页面:Android Material Design profile page,用ViewStub替换<include>,以便可以以编程方式在其中添加布局。

但是我明白了:

enter image description here

我该如何解决?

这是主要的活动文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example">

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

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:src="@drawable/ic_error"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.7" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_error"
    app:layout_anchor="@id/app_bar"
    app:layout_anchorGravity="bottom|end" />


<ViewStub
    android:id="@+id/profile_content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:visibility="visible" />

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

这是我希望在ViewStub内添加的布局:

    <?xml version="1.0" encoding="utf-8"?>
<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:layout_marginTop="@dimen/activity_horizontal_margin"
    android:padding="@dimen/activity_horizontal_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example">

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/selectableItemBackground"
            android:clickable="true"
            android:padding="@dimen/activity_horizontal_margin">

            <ImageView
                android:id="@+id/ivContactItem1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginEnd="@dimen/activity_horizontal_margin"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:src="@drawable/ic_rss_feed" />

            <TextView
                android:id="@+id/tvNumber1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:layout_toEndOf="@id/ivContactItem1"
                android:layout_toRightOf="@id/ivContactItem1"
                android:text="(123) 456-7890"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                android:textColor="#212121" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/tvNumber1"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:layout_marginTop="8dp"
                android:layout_toEndOf="@id/ivContactItem1"
                android:layout_toRightOf="@id/ivContactItem1"
                android:text="Home"
                android:textAppearance="@style/TextAppearance.AppCompat.Small"
                android:textColor="#727272" />

            <ToggleButton
                android:id="@+id/chkState1"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:background="@drawable/ic_rss_feed"
                android:checked="true"
                android:padding="6dp"
                android:textOff=""
                android:textOn="" />

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/selectableItemBackground"
            android:clickable="true"
            android:padding="@dimen/activity_horizontal_margin">

            <ImageView
                android:id="@+id/ivContactItem2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginEnd="@dimen/activity_horizontal_margin"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:src="@drawable/ic_rss_feed"
                android:visibility="invisible" />

            <TextView
                android:id="@+id/tvNumber2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:layout_toEndOf="@id/ivContactItem2"
                android:layout_toRightOf="@id/ivContactItem2"
                android:text="(321) 654-0987"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                android:textColor="#212121" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/tvNumber2"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:layout_marginTop="8dp"
                android:layout_toEndOf="@id/ivContactItem2"
                android:layout_toRightOf="@id/ivContactItem2"
                android:text="Work"
                android:textAppearance="@style/TextAppearance.AppCompat.Small"
                android:textColor="#727272" />

            <ToggleButton
                android:id="@+id/chkState2"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:background="@drawable/ic_rss_feed"
                android:checked="false"
                android:padding="6dp"
                android:textOff=""
                android:textOn="" />

        </RelativeLayout>

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/selectableItemBackground"
            android:clickable="true"
            android:padding="@dimen/activity_horizontal_margin">

            <ImageView
                android:id="@+id/ivContactItem3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginEnd="@dimen/activity_horizontal_margin"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:src="@drawable/ic_rss_feed" />

            <TextView
                android:id="@+id/tvNumber3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:layout_toEndOf="@id/ivContactItem3"
                android:layout_toLeftOf="@+id/chkState3"
                android:layout_toRightOf="@id/ivContactItem3"
                android:layout_toStartOf="@+id/chkState3"
                android:ellipsize="end"
                android:maxLines="1"
                android:text="chintan@letsnurture.com"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                android:textColor="#212121" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/tvNumber3"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:layout_marginTop="8dp"
                android:layout_toEndOf="@id/ivContactItem3"
                android:layout_toRightOf="@id/ivContactItem3"
                android:text="Home"
                android:textAppearance="@style/TextAppearance.AppCompat.Small"
                android:textColor="#727272" />

            <ToggleButton
                android:id="@+id/chkState3"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:background="@drawable/ic_rss_feed"
                android:checked="true"
                android:padding="6dp"
                android:textOff=""
                android:textOn="" />

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/selectableItemBackground"
            android:clickable="true"
            android:padding="@dimen/activity_horizontal_margin">

            <ImageView
                android:id="@+id/ivContactItem4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginEnd="@dimen/activity_horizontal_margin"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:src="@drawable/ic_rss_feed"
                android:visibility="invisible" />

            <TextView
                android:id="@+id/tvNumber4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:layout_toEndOf="@id/ivContactItem4"
                android:layout_toLeftOf="@+id/chkState4"
                android:layout_toRightOf="@id/ivContactItem4"
                android:layout_toStartOf="@+id/chkState4"
                android:ellipsize="end"
                android:maxLines="1"
                android:text="pratik@letsnurture.com"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                android:textColor="#212121" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/tvNumber4"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:layout_marginTop="8dp"
                android:layout_toEndOf="@id/ivContactItem4"
                android:layout_toRightOf="@id/ivContactItem4"
                android:text="Work"
                android:textAppearance="@style/TextAppearance.AppCompat.Small"
                android:textColor="#727272" />

            <ToggleButton
                android:id="@+id/chkState4"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:background="@drawable/ic_rss_feed"
                android:padding="6dp"
                android:textOff=""
                android:textOn="" />

        </RelativeLayout>

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/selectableItemBackground"
            android:clickable="true"
            android:padding="@dimen/activity_horizontal_margin">

            <ImageView
                android:id="@+id/ivContactItem5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginEnd="@dimen/activity_horizontal_margin"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:src="@drawable/ic_rss_feed" />

            <TextView
                android:id="@+id/tvNumber5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:layout_toEndOf="@id/ivContactItem5"
                android:layout_toLeftOf="@+id/chkState5"
                android:layout_toRightOf="@id/ivContactItem5"
                android:layout_toStartOf="@+id/chkState5"
                android:ellipsize="end"
                android:maxLines="1"
                android:text="202 Park Street, Los Angeles"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                android:textColor="#212121" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/tvNumber5"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:layout_marginTop="8dp"
                android:layout_toEndOf="@id/ivContactItem5"
                android:layout_toRightOf="@id/ivContactItem5"
                android:text="Home"
                android:textAppearance="@style/TextAppearance.AppCompat.Small"
                android:textColor="#727272" />

            <ToggleButton
                android:id="@+id/chkState5"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:background="@drawable/ic_rss_feed"
                android:checked="true"
                android:padding="6dp"
                android:textOff=""
                android:textOn="" />

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/selectableItemBackground"
            android:clickable="true"
            android:padding="@dimen/activity_horizontal_margin">

            <ImageView
                android:id="@+id/ivContactItem6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginEnd="@dimen/activity_horizontal_margin"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:src="@drawable/ic_rss_feed"
                android:visibility="invisible" />

            <TextView
                android:id="@+id/tvNumber6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:layout_toEndOf="@id/ivContactItem6"
                android:layout_toLeftOf="@+id/chkState6"
                android:layout_toRightOf="@id/ivContactItem6"
                android:layout_toStartOf="@+id/chkState6"
                android:ellipsize="end"
                android:maxLines="1"
                android:text="221B Baker Street, England"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                android:textColor="#212121" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/tvNumber6"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:layout_marginTop="8dp"
                android:layout_toEndOf="@id/ivContactItem6"
                android:layout_toRightOf="@id/ivContactItem6"
                android:text="Work"
                android:textAppearance="@style/TextAppearance.AppCompat.Small"
                android:textColor="#727272" />

            <ToggleButton
                android:id="@+id/chkState6"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:background="@drawable/ic_rss_feed"
                android:padding="6dp"
                android:textOff=""
                android:textOn="" />

        </RelativeLayout>

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="@dimen/activity_horizontal_margin">

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Send SMS" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/activity_horizontal_margin"
                android:layout_marginTop="@dimen/activity_horizontal_margin"
                android:text="Call" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/activity_horizontal_margin"
                android:layout_marginTop="@dimen/activity_horizontal_margin"
                android:text="Email" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/activity_horizontal_margin"
                android:layout_marginTop="@dimen/activity_horizontal_margin"
                android:text="Remove Contact" />

        </LinearLayout>
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

这是我用来将布局添加到ViewStub中的代码:

    ViewStub stub = (ViewStub) findViewById(R.id.profile_content);

    stub.setLayoutResource(R.layout.content_scrolling);
    stub.inflate();

1 个答案:

答案 0 :(得分:0)

尝试一下

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    >

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:src="@drawable/kid"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.7" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_online"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end" />


    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="@dimen/activity_horizontal_margin"
        android:padding="@dimen/activity_horizontal_margin"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        >

        <ViewStub
            android:id="@+id/profile_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="visible" />


    </android.support.v4.widget.NestedScrollView>

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

content_scrolling.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/selectableItemBackground"
        android:clickable="true"
        android:padding="@dimen/activity_horizontal_margin">

        <ImageView
            android:id="@+id/ivContactItem1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginEnd="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:src="@drawable/ic_online" />

        <TextView
            android:id="@+id/tvNumber1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_toEndOf="@id/ivContactItem1"
            android:layout_toRightOf="@id/ivContactItem1"
            android:text="(123) 456-7890"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            android:textColor="#212121" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/tvNumber1"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_marginTop="8dp"
            android:layout_toEndOf="@id/ivContactItem1"
            android:layout_toRightOf="@id/ivContactItem1"
            android:text="Home"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            android:textColor="#727272" />

        <ToggleButton
            android:id="@+id/chkState1"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:background="@drawable/ic_online"
            android:checked="true"
            android:padding="6dp"
            android:textOff=""
            android:textOn="" />

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/selectableItemBackground"
        android:clickable="true"
        android:padding="@dimen/activity_horizontal_margin">

        <ImageView
            android:id="@+id/ivContactItem2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginEnd="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:src="@drawable/ic_online"
            android:visibility="invisible" />

        <TextView
            android:id="@+id/tvNumber2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_toEndOf="@id/ivContactItem2"
            android:layout_toRightOf="@id/ivContactItem2"
            android:text="(321) 654-0987"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            android:textColor="#212121" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/tvNumber2"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_marginTop="8dp"
            android:layout_toEndOf="@id/ivContactItem2"
            android:layout_toRightOf="@id/ivContactItem2"
            android:text="Work"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            android:textColor="#727272" />

        <ToggleButton
            android:id="@+id/chkState2"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:background="@drawable/ic_online"
            android:checked="false"
            android:padding="6dp"
            android:textOff=""
            android:textOn="" />

    </RelativeLayout>


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/selectableItemBackground"
        android:clickable="true"
        android:padding="@dimen/activity_horizontal_margin">

        <ImageView
            android:id="@+id/ivContactItem3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginEnd="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:src="@drawable/ic_online" />

        <TextView
            android:id="@+id/tvNumber3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_toEndOf="@id/ivContactItem3"
            android:layout_toLeftOf="@+id/chkState3"
            android:layout_toRightOf="@id/ivContactItem3"
            android:layout_toStartOf="@+id/chkState3"
            android:ellipsize="end"
            android:maxLines="1"
            android:text="chintan@letsnurture.com"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            android:textColor="#212121" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/tvNumber3"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_marginTop="8dp"
            android:layout_toEndOf="@id/ivContactItem3"
            android:layout_toRightOf="@id/ivContactItem3"
            android:text="Home"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            android:textColor="#727272" />

        <ToggleButton
            android:id="@+id/chkState3"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:background="@drawable/ic_online"
            android:checked="true"
            android:padding="6dp"
            android:textOff=""
            android:textOn="" />

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/selectableItemBackground"
        android:clickable="true"
        android:padding="@dimen/activity_horizontal_margin">

        <ImageView
            android:id="@+id/ivContactItem4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginEnd="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:src="@drawable/ic_online"
            android:visibility="invisible" />

        <TextView
            android:id="@+id/tvNumber4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_toEndOf="@id/ivContactItem4"
            android:layout_toLeftOf="@+id/chkState4"
            android:layout_toRightOf="@id/ivContactItem4"
            android:layout_toStartOf="@+id/chkState4"
            android:ellipsize="end"
            android:maxLines="1"
            android:text="pratik@letsnurture.com"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            android:textColor="#212121" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/tvNumber4"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_marginTop="8dp"
            android:layout_toEndOf="@id/ivContactItem4"
            android:layout_toRightOf="@id/ivContactItem4"
            android:text="Work"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            android:textColor="#727272" />

        <ToggleButton
            android:id="@+id/chkState4"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:background="@drawable/ic_online"
            android:padding="6dp"
            android:textOff=""
            android:textOn="" />

    </RelativeLayout>


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/selectableItemBackground"
        android:clickable="true"
        android:padding="@dimen/activity_horizontal_margin">

        <ImageView
            android:id="@+id/ivContactItem5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginEnd="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:src="@drawable/ic_online" />

        <TextView
            android:id="@+id/tvNumber5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_toEndOf="@id/ivContactItem5"
            android:layout_toLeftOf="@+id/chkState5"
            android:layout_toRightOf="@id/ivContactItem5"
            android:layout_toStartOf="@+id/chkState5"
            android:ellipsize="end"
            android:maxLines="1"
            android:text="202 Park Street, Los Angeles"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            android:textColor="#212121" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/tvNumber5"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_marginTop="8dp"
            android:layout_toEndOf="@id/ivContactItem5"
            android:layout_toRightOf="@id/ivContactItem5"
            android:text="Home"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            android:textColor="#727272" />

        <ToggleButton
            android:id="@+id/chkState5"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:background="@drawable/ic_online"
            android:checked="true"
            android:padding="6dp"
            android:textOff=""
            android:textOn="" />

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/selectableItemBackground"
        android:clickable="true"
        android:padding="@dimen/activity_horizontal_margin">

        <ImageView
            android:id="@+id/ivContactItem6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginEnd="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:src="@drawable/ic_online"
            android:visibility="invisible" />

        <TextView
            android:id="@+id/tvNumber6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_toEndOf="@id/ivContactItem6"
            android:layout_toLeftOf="@+id/chkState6"
            android:layout_toRightOf="@id/ivContactItem6"
            android:layout_toStartOf="@+id/chkState6"
            android:ellipsize="end"
            android:maxLines="1"
            android:text="221B Baker Street, England"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            android:textColor="#212121" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/tvNumber6"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_marginTop="8dp"
            android:layout_toEndOf="@id/ivContactItem6"
            android:layout_toRightOf="@id/ivContactItem6"
            android:text="Work"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            android:textColor="#727272" />

        <ToggleButton
            android:id="@+id/chkState6"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:background="@drawable/ic_online"
            android:padding="6dp"
            android:textOff=""
            android:textOn="" />

    </RelativeLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="@dimen/activity_horizontal_margin">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Send SMS" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/activity_horizontal_margin"
            android:layout_marginTop="@dimen/activity_horizontal_margin"
            android:text="Call" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/activity_horizontal_margin"
            android:layout_marginTop="@dimen/activity_horizontal_margin"
            android:text="Email" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/activity_horizontal_margin"
            android:layout_marginTop="@dimen/activity_horizontal_margin"
            android:text="Remove Contact" />

    </LinearLayout>
</LinearLayout>

输出

enter image description here