Closed SjAndy88 closed 7 years ago
参考 demo apk 实战 使用 margin ,在本框架中,padding 只对列表有效,对Header无效
你的意思要实现类似效果需要在布局里面自定义个header? 然后在代码里面给header设置margin是吗? 是否能够直接通过SmartRefreshLayout去拿header而不用自己定义header?
可以,不需要自定义Header ,请下载 demo 查看 demo 对margin 的使用方法
不自定义Header,使用默认的Header直接显示
refreshLayout.getLayout().post(new Runnable() {
@Override
public void run() {
RefreshHeader refreshHeader = refreshLayout.getRefreshHeader();
if (refreshHeader != null) {
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) refreshHeader.getView().getLayoutParams();
layoutParams.setMargins(0, getResources().getDimensionPixelOffset(R.dimen.bar_height), 0, 0);
StatusBarUtil.setMargin(RepastPracticeActivity.this, refreshHeader.getView());
}
}
});
@scwang90 请问这个问题怎么弄?
请看 这个截图页面的 xml 代码,里面有设置 margin
不只是这个页面,在实战中 所有页面都有在 xml 中 设置 margin
<?xml version="1.0" encoding="utf-8"?> <FrameLayout 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="@color/colorBackgroudDark" tools:context="com.scwang.refreshlayout.activity.practice.RepastPracticeActivity">
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srlEnableAutoLoadmore="true"
app:srlEnablePreviewInEditMode="true">
<!--<pl.droidsonroids.gif.GifImageView-->
<!--android:id="@+id/gifview"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_marginTop="@dimen/bar_height"-->
<!--android:scaleType="centerCrop"-->
<!--android:src="@mipmap/gif_header_repast"-->
<!--app:srlSpinnerStyle="Scale"/>-->
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="@dimen/bar_height"
tools:listitem="@layout/listitem_practive_repast"/>
<!--<com.scwang.smartrefresh.layout.footer.ClassicsFooter-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--app:srlAccentColor="#888"/>-->
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
<com.github.mmin18.widget.RealtimeBlurView
android:id="@+id/blurview"
android:layout_width="match_parent"
android:layout_height="@dimen/bar_height"
android:visibility="visible"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/AppTheme.Toolbar.Light"
android:layout_width="match_parent"
android:layout_height="@dimen/bar_height"
android:background="@android:color/transparent"
app:navigationIcon="@drawable/ic_arrow_back_dark_24dp"
app:title="@string/title_activity_practice_repast"/>
android:layout_marginTop="dimen/bar_height"
就是这个
因为我的头和尾布局都是在Application中全局定义了,所以不先在布局里面再单独写,所以就直接通过上的的代码区获取RefreshHeader refreshHeader = refreshLayout.getRefreshHeader();中的headerView,并且代码设置marginTop,然后就出现上面截图的情况了。
全局设置和xml不冲突的,你直接诶在xml 加上 margin 就可以了。 还有,你的截图看起来很正常,没问题
顶部那个刷新头部直接就可以看到啊,这个也ok?
你的用法,不对,你要和 demo一样使用拉伸的样式
app:srlSpinnerStyle="Scale"
在demo的基础上将pl.droidsonroids.gif.GifImageView改为下面ClassicsHeader <com.scwang.smartrefresh.layout.header.ClassicsHeader android:id="@+id/gifview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="?attr/actionBarSize" app:srlSpinnerStyle="Scale"/>
ClassicsHeader 好像不支持这个Scale?
经典需要用 app:srlClassicsSpinnerStyle
了解, 谢谢
因为设计原因需要让SmartRefreshLayout有个paddingTop,但是在刷新的时候希望可以在padding区域进行动画效果,这个TwinklingRefreshLayout是实现了的,更换到SmartRefreshLayout就不行了。