set location for progressbar in swipe refresh layout android

邮差的信 提交于 2019-12-08 17:11:42

问题


I used Swipe refresh layout in my app. It worked but I want set location for progress bar in swipe layout margin top 100 px. I don't want use default location of it. How I do? thank you


回答1:


You could set the offset from top using this setProgressViewOffset (boolean scale, int start, int end)

You can read about it here.




回答2:


In folder res/values create an xml file if you have not already called dimens.xml

Then you can have in it:

<resources>
    <dimen name="refresher_offset">your_preferred_offset_in_dp</dimen>
    <dimen name="refresher_offset_end">how_long_in_dp_the_swipe</dimen>
</resources>

Then take the SwipeRefreshLayout that you have inflated and add on onCreate if you are in Activity or onCreateView if you are in fragment:

swipeRefreshLayout.setProgressViewOffset(false, 
  getResources().getDimensionPixelSize(R.dimen.refresher_offset),    
  getResources().getDimensionPixelSize(R.dimen.refresher_offset_end));

Alternatively you can replace the dimen constants with just a number, but that will mean pixels and the relative position will be different making the implementation problematic in different devices.



来源:https://stackoverflow.com/questions/33797192/set-location-for-progressbar-in-swipe-refresh-layout-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!