从开源库ActionsContentView提取效果

项目地址:https://github.com/StevenRudenko/ActionsContentView

我比较喜欢里面的effect_replace 效果。所以今天花了点时间把他提取出来,结合Fragment 使用。

先看下屏幕截图,,没做gif,所以大家有兴趣可以自己试试效果:

原效果:

提取效果:

先说下其中Fragment的使用

最开始我新建了个基类BaseFragment,用于放公共方法:

package com.example.androidfragmenttest;import android.app.Fragment;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;/** * @author delvikCoder 基类,方法重用可以放在这里 */public abstract class BaseFragment extends Fragment {private FragmentActivity activity;public View childMainView;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);activity = (FragmentActivity) getActivity();childMainView = activity.getLayoutView(getLayoutId());createChildView(savedInstanceState);}@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {return LayoutView;}public abstract void createChildView(Bundle savedInstanceState);public abstract int getLayoutId();}

子类继承并实现该方法:

public abstract void createChild(Bundle savedInstanceState);public abstract int getLayoutId();但是这样做有个缺点,在切换的时候,子Fragment的视图总是在重新加载,如果操作过多会导致UI卡顿,因此这不是个好方法。

于是之前看到一篇讲Fragment的按例,再次研究了下。他的简洁天气我也比较喜欢。

参考地址:

因此我修改了下主类MenuActivity 由于时间有限,所以我有些地方是模仿操作,感觉我的代码还需要更简洁化。傻X的全模仿那是不行的。

这里,再说下,viewActionsContentView的使用

<shared.ui.actionscontentview.ActionsContentView xmlns:android=""xmlns:app=""android:id="@+id/actionsContentView"android:layout_width="match_parent"android:layout_height="match_parent"app:actions_layout="@layout/effect_actions"app:actions_spacing="0dp"app:content_layout="@layout/main_content"app:effect_actions="@anim/effect_replace_actions"app:effect_content="@anim/effect_replace_content"app:fade_max_value="@integer/default_pref_fade_max_value"app:fade_type="both"app:fling_duration="@integer/default_pref_fling_delay"app:spacing="0dp"app:swiping_type="full" /> app:actions_layout="@layout/effect_actions"这个是菜单列表的layout,很简单的布局,一个标题一个菜单listview<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=""android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/actions_bg" ><includeandroid:id="@+id/title"android:layout_width="match_parent"android:layout_height="wrap_content"layout="@layout/category_list_item" /><ListViewandroid:id="@+id/actions"android:layout_width="match_parent"android:layout_height="0dp"android:layout_alignParentBottom="true"android:layout_below="@id/title"android:cacheColorHint="@color/actions_bg"android:divider="@null"android:listSelector="@drawable/item_background_holo_light" /></RelativeLayout> app:content_layout="@layout/main_content"这个是Fragment的父容器。在里面可以添加头部标题栏,或者更多操作。<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=""android:layout_width="match_parent"android:layout_height="match_parent"android:background="@android:color/white"android:orientation="vertical" ><FrameLayoutandroid:id="@+id/content"android:layout_width="fill_parent"android:layout_height="fill_parent" ></FrameLayout></LinearLayout>就是去旅行。牵着彼此的手,

从开源库ActionsContentView提取效果

相关文章:

你感兴趣的文章:

标签云: