Android 安卓studio 1.4默认导航抽屉,警告主线程需要大量工作
我是android新手,我在studio 1.4中使用默认的导航抽屉,我的问题是当我更改nav_header_main.xml文件时,我的导航抽屉没有正常移动,在更改xml后,我在logo cat中收到警告 主线程做了这么多的工作,任何人请帮助如何提高我的导航抽屉的性能和如何获得平滑滚动任何人请帮助我 当我在nav_header_main.xml中使用profile pic时,如果没有PRPIC文件,我将面临这个问题,它将平滑滚动 这是我的错误Android 安卓studio 1.4默认导航抽屉,警告主线程需要大量工作,android,multithreading,android-studio,navigation-drawer,Android,Multithreading,Android Studio,Navigation Drawer,我是android新手,我在studio 1.4中使用默认的导航抽屉,我的问题是当我更改nav_header_main.xml文件时,我的导航抽屉没有正常移动,在更改xml后,我在logo cat中收到警告 主线程做了这么多的工作,任何人请帮助如何提高我的导航抽屉的性能和如何获得平滑滚动任何人请帮助我 当我在nav_header_main.xml中使用profile pic时,如果没有PRPIC文件,我将面临这个问题,它将平滑滚动 这是我的错误 Skipped 42 frames! The
Skipped 42 frames! The application may be doing too much work on its main thread.
主课
公共类MainActivity扩展了AppCompatActivity
实现NavigationView.OnNavigationItemSelectedListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camara) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
nav_header_main.xml
android:layout_width="match_parent"
android:layout_height="190dp"
android:background="@drawable/bghdpi"
android:orientation="vertical"
>
<ImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/flag"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comp. Sci. Tutorials"
android:textSize="14sp"
android:textColor="#FFF"
android:textStyle="bold"
android:gravity="center"
android:paddingBottom="4dp"
android:id="@+id/username"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_above="@+id/email"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="user@host.com"
android:id="@+id/email"
android:gravity="center"
android:layout_marginBottom="8dp"
android:textSize="14sp"
android:textColor="#fff"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/username"
android:layout_alignStart="@+id/username"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
android:layout\u width=“match\u parent”
android:layout_height=“190dp”
android:background=“@drawable/bghdpi”
android:orientation=“垂直”
>
在主线程中启动一个新线程,让它完成所有工作。Main应该只初始化你的应用程序,不执行任何其他逻辑。在问题中发布你的代码请发布你的代码查看我的代码