Android 如何在垂直视图寻呼机的顶部添加页边距?
我正在尝试实现垂直视图寻呼机,如“Happn”应用程序 这是我的自定义ViewPager类 VerticalViewPager.java 试试下面的代码Android 如何在垂直视图寻呼机的顶部添加页边距?,android,android-layout,android-viewpager,Android,Android Layout,Android Viewpager,我正在尝试实现垂直视图寻呼机,如“Happn”应用程序 这是我的自定义ViewPager类 VerticalViewPager.java 试试下面的代码 viewPager.setClipToPadding(false); viewPager.setPadding(70, 30, 170, 30);//left,top,right,bottom in px viewPager.setPageMargin(30); 这将根据需要设置填充,这一个适合我。 试试看,一定要让
viewPager.setClipToPadding(false);
viewPager.setPadding(70, 30, 170, 30);//left,top,right,bottom in px
viewPager.setPageMargin(30);
这将根据需要设置填充,这一个适合我。
试试看,一定要让我知道它是否适合您**my viewpager item xml**
**my viewpager item xml**
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@color/dim_white"
android:layout_height="match_parent">
<android.support.v7.widget.CardView 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:id="@+id/card_view"
style="@style/CardStyle.ContactList"
android:layout_width="match_parent"
android:layout_marginBottom="60dp"
android:layout_marginTop="60dp"
android:layout_marginLeft="22dp"
android:layout_marginRight="22dp"
app:cardCornerRadius="20dp"
android:layout_height="match_parent">
<ImageView
android:id="@+id/profile_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/logo_3_1" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="80dp"
android:gravity="center_horizontal"
android:text="Sardar"
android:textColor="@color/white"
android:textSize="@dimen/letter_large" />
</android.support.v7.widget.CardView>
</FrameLayout>
**My parent layout :**
<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="wrap_content"
android:orientation="vertical"
">
<RelativeLayout
android:id="@+id/empty_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dim_white"
android:visibility="gone">
<ImageView
android:id="@+id/add_photo"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:src="@drawable/favpholder"
android:textSize="@dimen/verify_phone_number_text_size" />
<TextView
android:id="@+id/no_fav_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/add_photo"
android:layout_marginLeft="@dimen/spacing_24_dp"
android:layout_marginTop="@dimen/spacing_medium"
android:layout_marginRight="@dimen/spacing_24_dp"
android:gravity="center"
android:text="@string/no_followers"
android:textAlignment="center"
android:textAppearance="@style/TextStyle.Medium"
android:textColor="@color/slate"
android:textSize="@dimen/letter_large" />
</RelativeLayout>
<android.support.v7.widget.CardView
android:id="@+id/search_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/search_bar_height"
android:layout_below="@id/empty_layout"
android:layout_margin="@dimen/spacing_medium">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/search_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_small"
android:src="@drawable/ic_search_black_24dp" />
<TextView
android:id="@+id/search_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_margin="@dimen/spacing_xsmall"
android:layout_toEndOf="@id/search_icon"
android:gravity="center"
android:text="@string/search_contacts" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<custom.VerticalViewPager
android:layout_below="@id/search_bar"
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
**我的父布局:**
嗨,谢谢你的友好回复。不幸的是,它不起作用。你能用默认的ViewPager而不是自定义的ViewPager来尝试一下这段代码吗?我已经添加了xml文件
viewPager.setClipToPadding(false);
viewPager.setPadding(70, 30, 170, 30);//left,top,right,bottom in px
viewPager.setPageMargin(30);
**my viewpager item xml**
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@color/dim_white"
android:layout_height="match_parent">
<android.support.v7.widget.CardView 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:id="@+id/card_view"
style="@style/CardStyle.ContactList"
android:layout_width="match_parent"
android:layout_marginBottom="60dp"
android:layout_marginTop="60dp"
android:layout_marginLeft="22dp"
android:layout_marginRight="22dp"
app:cardCornerRadius="20dp"
android:layout_height="match_parent">
<ImageView
android:id="@+id/profile_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/logo_3_1" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="80dp"
android:gravity="center_horizontal"
android:text="Sardar"
android:textColor="@color/white"
android:textSize="@dimen/letter_large" />
</android.support.v7.widget.CardView>
</FrameLayout>
**My parent layout :**
<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="wrap_content"
android:orientation="vertical"
">
<RelativeLayout
android:id="@+id/empty_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dim_white"
android:visibility="gone">
<ImageView
android:id="@+id/add_photo"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:src="@drawable/favpholder"
android:textSize="@dimen/verify_phone_number_text_size" />
<TextView
android:id="@+id/no_fav_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/add_photo"
android:layout_marginLeft="@dimen/spacing_24_dp"
android:layout_marginTop="@dimen/spacing_medium"
android:layout_marginRight="@dimen/spacing_24_dp"
android:gravity="center"
android:text="@string/no_followers"
android:textAlignment="center"
android:textAppearance="@style/TextStyle.Medium"
android:textColor="@color/slate"
android:textSize="@dimen/letter_large" />
</RelativeLayout>
<android.support.v7.widget.CardView
android:id="@+id/search_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/search_bar_height"
android:layout_below="@id/empty_layout"
android:layout_margin="@dimen/spacing_medium">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/search_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_small"
android:src="@drawable/ic_search_black_24dp" />
<TextView
android:id="@+id/search_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_margin="@dimen/spacing_xsmall"
android:layout_toEndOf="@id/search_icon"
android:gravity="center"
android:text="@string/search_contacts" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<custom.VerticalViewPager
android:layout_below="@id/search_bar"
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>