gpt4 book ai didi

android - 抽屉导航打开和关闭的自定义动画

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:10:00 43 4
gpt4 key购买 nike

让我们做一些具有挑战性的事情。我看过这个抽屉导航的动画: enter image description here

我想实现它,因为它的效果很好。我试图通过创建自定义 View 来获得效果,并且在触摸时我获得了至少 50% 的相似效果。我想从我的自定义 View 到导航 View 实现我的 ondraw() 和 ontouch() 方法。这是怎么做到的?任何人有任何线索?任何人都可以提供任何具有相似内容的链接。

我已经试过了:

public class CustomNavigation extends DrawerLayout {

public CustomNavigation(Context context) {
super(context);
}

public CustomNavigation(Context context, AttributeSet attrs) {
super(context, attrs);
}

public CustomNavigation(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// invalidate();
}
public void start()
{
this.invalidate();
Log.d("Parth", "start");
}

@Override
public void onDraw(Canvas c) {
Log.d("Parth", "ondraw");
// super.onDraw(c);

}

}

未调用 on draw 方法。为什么会这样?

从主 Activity 我创建了一个上面类的对象并像这样调用启动方法:

CustomNavigation drawer = (CustomNavigation) findViewById(R.id.drawer_layout);
drawer.start();

这只是最初的东西,我还想实现这些:

最佳答案

所以在找到这么多之后,我终于找到了一个图书馆,这里是 link给它。我不知道为什么这么难找。或者对于那些希望使用它的人来说,这只是我糟糕的一周,你可以在这里找到图书馆。如果您需要,我还会提供更多实现:

main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<com.mxn.soul.flowingdrawer_core.LeftDrawerLayout
android:id="@+id/id_drawerlayout"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"

>

<!--content-->
<android.support.design.widget.CoordinatorLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</android.support.design.widget.CoordinatorLayout>

<!--menu-->
<RelativeLayout
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:clipChildren="false"
>
<com.mxn.soul.flowingdrawer_core.FlowingView
android:paddingRight="35dp"
android:id="@+id/sv"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<FrameLayout
android:id="@+id/id_container_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_marginRight="25dp"

/>
</RelativeLayout>

</com.mxn.soul.flowingdrawer_core.LeftDrawerLayout>

主要 Activity .java

public class MainActivity extends AppCompatActivity{

private LeftDrawerLayout mLeftDrawerLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mLeftDrawerLayout = (LeftDrawerLayout) findViewById(R.id.id_drawerlayout);

FragmentManager fm = getSupportFragmentManager();
MyMenuFragment mMenuFragment = (MyMenuFragment) fm.findFragmentById(R.id.id_container_menu);
FlowingView mFlowingView = (FlowingView) findViewById(R.id.sv);
if (mMenuFragment == null) {
fm.beginTransaction().add(R.id.id_container_menu, mMenuFragment = new MyMenuFragment()).commit();
}
mLeftDrawerLayout.setFluidView(mFlowingView);
mLeftDrawerLayout.setMenuFragment(mMenuFragment);
}


}

现在导航 View 在这里被认为是一个 fragment ,所以 fragment 的代码在这里:

public class MyMenuFragment extends MenuFragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment,container,false);

return setupReveal(v);
}
}

差不多就是这样了。你可以感谢this person为了出色的工作。

关于android - 抽屉导航打开和关闭的自定义动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35448807/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com