我想在我的应用程序底部实现一个菜单栏,就像我在很多主要应用程序中看到的那样,如facebook,google +,stumble等。(见下图)
这方面的关键方面是它叠加在实际内容之上,当你向下滚动时,它会消失,但是当你向上滚动它会回来。
由于一堆应用程序使用这种构造,我想知道是否有一种简单的方法可以做到这一点,我只是遗漏了一些东西,或者它实际上是非常复杂但是这些大公司只是雇用了很好的开发商?
任何关于如何解决这个问题的提示都将受到赞赏。
答案 0 :(得分:7)
此模式通常称为" QuickReturn UI"。很少有开源实现可以查看,即QuickReturnListView
答案 1 :(得分:0)
我已经实现了Facebook中的QuickReturn UI模式。
您可以在此处查看更多示例 - > https://github.com/lawloretienne/QuickReturn
public class QuickReturnFacebookFragment extends Fragment {
// region Member Variables
private String[] mAvatarUrls;
private String[] mDisplayNames;
private String[] mTimestamps;
private String[] mMessages;
private String[] mPostImageUrls;
private int[] mCommentCounts;
private int[] mLikeCounts;
@InjectView(R.id.rv)
RecyclerView mRecyclerView;
@InjectView(R.id.quick_return_footer_ll)
LinearLayout mQuickReturnFooterLinearLayout;
@InjectView(R.id.quick_return_header_tv)
TextView mQuickReturnHeaderTextView;
// endregion
//region Listeners
//endregion
// region Constructors
public static QuickReturnFacebookFragment newInstance() {
QuickReturnFacebookFragment fragment = new QuickReturnFacebookFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
public QuickReturnFacebookFragment() {
}
// endregion
// region Lifecycle Methods
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAvatarUrls = getActivity().getResources().getStringArray(R.array.avatar_urls);
mDisplayNames = getActivity().getResources().getStringArray(R.array.display_names);
mTimestamps = getActivity().getResources().getStringArray(R.array.facebook_timestamps);
mMessages = getActivity().getResources().getStringArray(R.array.facebook_messages);
mPostImageUrls = getActivity().getResources().getStringArray(R.array.facebook_post_image_urls);
mCommentCounts = getActivity().getResources().getIntArray(R.array.facebook_comment_counts);
mLikeCounts = getActivity().getResources().getIntArray(R.array.facebook_like_counts);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_quick_return_facebook, container, false);
ButterKnife.inject(this, view);
return view;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ArrayList<FacebookPost> posts = new ArrayList<>();
for(int i=0; i<23; i++){
FacebookPost post = new FacebookPost();
post.setAvatarUrl(mAvatarUrls[i]);
post.setDisplayName(mDisplayNames[i]);
post.setTimestamp(mTimestamps[i]);
post.setCommentCount(mCommentCounts[i]);
post.setLikeCount(mLikeCounts[i]);
post.setPostImageUrl(mPostImageUrls[i]);
post.setMessage(mMessages[i]);
posts.add(post);
}
FacebookAdapter adapter = new FacebookAdapter(getActivity(), posts);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setAdapter(adapter);
mRecyclerView.addItemDecoration(new SpacesItemDecoration(QuickReturnUtils.dp2px(getActivity(), 8)));
int headerHeight = getResources().getDimensionPixelSize(R.dimen.facebook_header_height);
int footerHeight = getResources().getDimensionPixelSize(R.dimen.facebook_footer_height);
int headerTranslation = -headerHeight;
int footerTranslation = -footerHeight;
QuickReturnRecyclerViewOnScrollListener scrollListener = new QuickReturnRecyclerViewOnScrollListener.Builder(QuickReturnViewType.BOTH)
.header(mQuickReturnHeaderTextView)
.minHeaderTranslation(headerTranslation)
.footer(mQuickReturnFooterLinearLayout)
.minFooterTranslation(-footerTranslation)
.isSnappable(true)
.build();
mRecyclerView.setOnScrollListener(scrollListener);
}
@Override
public void onDestroyView() {
super.onDestroyView();
ButterKnife.reset(this);
}
// endregion
}