文章标题

xiaoxiao2021-02-27  217

import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.widget.RelativeLayout; import android.widget.TextView; import me.tangke.slidemenu.SlideMenu; public class MainActivity extends BaseActivity { private RelativeLayout rl; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); rl = (RelativeLayout) findViewById(R.id.rl); playAnim(rl); } private void playAnim(View view){ AlphaAnimation alphaAnimation = new AlphaAnimation(1,0); alphaAnimation.setDuration(2000); view.startAnimation(alphaAnimation); alphaAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { //动画结束,跳转 Intent intent = new Intent(MainActivity.this,HomeActivity.class); startActivity(intent); } @Override public void onAnimationRepeat(Animation animation) { } }); } } public class BaseActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); //隐藏标题栏 getSupportActionBar().hide(); } } public class HomeActivity extends BaseActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); SlideMenu slideMenu = new SlideMenu(this); setContentView(slideMenu); initSlideMenu(slideMenu); } /** * 初始化slidemenu菜单0 */ private void initSlideMenu(SlideMenu slideMenu) { //Setup the content //显示内容页面 TextView contentView = new TextView(this); contentView.setText("这是内容"); slideMenu.addView(contentView, new SlideMenu.LayoutParams( SlideMenu.LayoutParams.MATCH_PARENT, SlideMenu.LayoutParams.MATCH_PARENT, SlideMenu.LayoutParams.ROLE_CONTENT)); // Setup the primary 这个左边侧滑菜单 TextView primaryMenu = new TextView(this); primaryMenu.setText("这是左侧滑"); slideMenu.addView(primaryMenu, new SlideMenu.LayoutParams(300, SlideMenu.LayoutParams.MATCH_PARENT, SlideMenu.LayoutParams.ROLE_PRIMARY_MENU)); // Setup the secondary menu 右边侧滑菜单 TextView secondaryMenu = new TextView(this); secondaryMenu.setText("这是右侧滑"); slideMenu.addView(secondaryMenu, new SlideMenu.LayoutParams(300, SlideMenu.LayoutParams.MATCH_PARENT, SlideMenu.LayoutParams.ROLE_SECONDARY_MENU)); } } <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/rl" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.bwie.newsinfo.MainActivity"> <ImageView android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> </RelativeLayout>
转载请注明原文地址: https://www.6miu.com/read-10975.html

最新回复(0)