如何删除viewpager和cardview之间的空间区域?

时间:2018-02-15 07:57:59

标签: android android-viewpager cardview

我在nestedscrollview中的viewpager下使用了cardview。但是,我无法删除这些项目之间的空间区域。

你能帮我解决一下如何删除viewpager和id / deleteGroupCardView之间的空间吗?我添加了模拟器的截图更容易理解。

Here is the ss of emulator view

 <?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"
 tools:context="uur.com.pinbook.Activities.DisplayGroupDetail">


 <android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="@color/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/groupPictureImgv"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            android:src="@drawable/mountain_pic"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:actionBarSize"
            android:elevation="7dp"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
   </android.support.v7.widget.Toolbar>

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

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

<!--include layout="@layout/group_nested_scroll_view"/-->

<android.support.v4.widget.NestedScrollView
    android:id="@+id/nestedScrollViewContent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:minHeight="600dp"
        android:orientation="vertical">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:orientation="horizontal"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="25dp"
            app:cardCornerRadius="5dp"
            android:id="@+id/addFriendCardView"
            android:visibility="gone">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center">

                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_gravity="center"
                    android:layout_marginLeft="5dp"
                    android:src="@drawable/add_user_to_group_img" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="   Katilimci Ekle"
                    android:layout_gravity="center"/>
            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:orientation="horizontal"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="5dp"
            app:cardCornerRadius="5dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text=" Katilimci sayisi: "
                    android:gravity="center"/>

                <TextView
                    android:id="@+id/personCntTv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"/>

            </LinearLayout>
        </android.support.v7.widget.CardView>

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <android.support.v7.widget.CardView
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:orientation="horizontal"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            app:cardCornerRadius="5dp"
            android:id="@+id/deleteGroupCardView"
            card_view:cardMaxElevation="0dp"
            card_view:cardElevation="0dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="GRUBU SIL"/>

            </LinearLayout>
        </android.support.v7.widget.CardView>

    </LinearLayout>

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

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

2 个答案:

答案 0 :(得分:1)

您只需将父级布局设为Relative layout,然后将Id's提供给cardviewviewpager,然后对此类元素使用android:layout_below="" ...

 <?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"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nestedScrollViewContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <RelativeLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minHeight="600dp"
            android:orientation="vertical">

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:orientation="horizontal"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="25dp"
                app:cardCornerRadius="5dp"
                android:id="@+id/addFriendCardView"
                android:visibility="gone">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center">

                    <ImageView
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:layout_gravity="center"
                        android:layout_marginLeft="5dp"
                        android:src="@drawable/ic_noti" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="   Katilimci Ekle"
                        android:layout_gravity="center"/>
                </LinearLayout>

            </android.support.v7.widget.CardView>

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:id="@+id/asd"
                android:layout_below="@+id/addFriendCardView"
                android:orientation="horizontal"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="5dp"
                app:cardCornerRadius="5dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text=" Katilimci sayisi: "
                        android:gravity="center"/>

                    <TextView
                        android:id="@+id/personCntTv"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"/>

                </LinearLayout>
            </android.support.v7.widget.CardView>

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_below="@+id/asd"
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:layout_weight="1" />

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:layout_below="@+id/viewpager"
                android:orientation="horizontal"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="5dp"
                app:cardCornerRadius="5dp"
                android:id="@+id/deleteGroupCardView">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="GRUBU SIL"/>

                </LinearLayout>
            </android.support.v7.widget.CardView>

        </RelativeLayout>

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

你的输出就像这样......

enter image description here

答案 1 :(得分:1)

<?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"

    android:id="@+id/nestedScrollViewContent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:minHeight="600dp"
        android:orientation="vertical">

        <android.support.v7.widget.CardView
            android:id="@+id/addFriendCardView"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="25dp"
            android:orientation="horizontal"
            android:visibility="gone"
            app:cardCornerRadius="5dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center">

                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_gravity="center"
                    android:layout_marginLeft="5dp"
                    android:src="@android:color/darker_gray" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text="   Katilimci Ekle" />
            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="5dp"
            android:orientation="horizontal"
            app:cardCornerRadius="5dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text=" Katilimci sayisi: " />

                <TextView
                    android:id="@+id/personCntTv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center" />

            </LinearLayout>
        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:id="@+id/deleteGroupCardView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            app:cardCornerRadius="5dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal">

                <android.support.v4.view.ViewPager
                    android:id="@+id/viewpager"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_above="@+id/text_view_one" />

                <TextView
                    android:id="@+id/text_view_one"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_margin="5dp"
                    android:text="GRUBU SIL" />

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

    </LinearLayout>

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