我正在制作一个 android 启动器,我需要知道如何将所有应用程序加载到 gridview 中。我希望像计算器这样的系统东西也能显示出来。我怎样才能做到这一点?我已经搜索了很长时间没有任何解决方案。请帮助我,非常感谢!
Java代码:
package com.mysoftware.mysoftwareos.launcher;
import java.util.List;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.GridView;
import android.widget.LinearLayout;
public class AllAppsActivity extends Activity {
LinearLayout allappsLayout;
GridView allappsGridView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.allapps_screen);
//Import views
allappsLayout = (LinearLayout)findViewById(R.id.allappsLayout);
allappsGridView = (GridView)findViewById(R.id.allappsGridView);
//Setup animation for the main layout
Animation a = AnimationUtils.loadAnimation(this, R.anim.fadeout);
a.reset();
allappsLayout.clearAnimation();
allappsLayout.startAnimation(a);
//Load all apps into the apptray
}
}
我的xml布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/allappsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/wallpaper"
android:orientation="vertical" >
<GridView
android:id="@+id/allappsGridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3" >
</GridView>
</LinearLayout>