Android ViewPager 页面片段之间的填充/边距 [英] Android ViewPager padding/margin between page fragments

查看:34
本文介绍了Android ViewPager 页面片段之间的填充/边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android Market/Google Music 似乎能够在 ViewPager 中包含的不同片段之间存在某种差距.

Android Market/Google Music seem to be able to have a gap of some sort between the different fragments that are contained in the ViewPager.

知道这是怎么做到的吗?向实际片段视图添加边距/填充不起作用,因为视图仍然需要占据屏幕的整个宽度.'gap' 仅在滑动 ViewPager 时可见.

Any idea how this is done? Adding margin/padding to the actual fragment view doesn't work, because the view still needs to occupy the entire width of the screen. The 'gap' is only visible when swiping the ViewPager.

推荐答案

支持包中,r4 你可以使用这些方法:

In Support Package, r4 you can use these methods:

setPageMargin(int marginPixels)
setPageMarginDrawable(Drawable)
setPageMarginDrawable(int)

ViewPager 类中.

我不知道为什么这在 XML 中没有等价物 :-(

I don't know why this doesn't have equivalent in XML :-(

如果您需要使用浸入装置,您可以使用此方法:

If you need use dip unit you can use this method:

public static int convertDip2Pixels(Context context, int dip) {
    return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, context.getResources().getDisplayMetrics());
}

这篇关于Android ViewPager 页面片段之间的填充/边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆