編輯:關於android開發
package com.example.yanlei.my1; import android.app.AlertDialog; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private MainActivity ard=this; private LinearLayout mainView=null; private TextView tv=null; private GridView gv=null; private int id=0x01080000; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mainView=new LinearLayout(this); mainView.setOrientation(LinearLayout.VERTICAL); tv=new TextView(this); tv.setText("這裡顯示圖標名稱和id及其尺寸"); gv_init(); mainView.addView(tv); mainView.addView(gv); setContentView(mainView); } /*gv初始化*/ void gv_init(){ gv=new GridView(this); GridView.LayoutParams lp=new GridView.LayoutParams(-1,-1); gv.setLayoutParams(lp); gv.setNumColumns(GridView.AUTO_FIT); gv.setVerticalSpacing(10); gv.setHorizontalSpacing(10); gv.setAdapter(new ImageAdapter(this)); gv.setFocusableInTouchMode(true); gv.setOnItemClickListener(new OnItemClickListener(){ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) { tv.setText("圖標名稱:"+ard.getResources().getResourceEntryName(0x01080000+arg2)+"\n"); tv.append("圖標Id:0x"+Integer.toHexString(0x10800000+arg2)+"\n"); tv.append("圖標大小:"+arg1.getWidth()+"x"+arg1.getHeight()+"\n"); } }); gv.setOnItemSelectedListener(new OnItemSelectedListener(){ public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) { tv.setText("圖標名稱:"+ard.getResources().getResourceEntryName(0x01080000+arg2)+"\n"); tv.append("圖標Id:0x"+Integer.toHexString(0x10800000+arg2)+"\n"); tv.append("圖標大小:"+arg1.getWidth()+"x"+arg1.getHeight()+"\n"); } public void onNothingSelected(AdapterView<?> arg0) { } }); } class MyThread extends Thread{ } /*ImageAdapter*/ public class ImageAdapter extends BaseAdapter { private Context context; public ImageAdapter(Context c) {context = c;} public int getCount() {return 152;} public Object getItem(int position) {return position;} public long getItemId(int position) {return position;} public View getView(int position, View convertView, ViewGroup parent) { ImageView iv = new ImageView(context); iv.setLayoutParams(new GridView.LayoutParams(-2,-2)); id=0x01080000+position; iv.setImageResource(id); iv.setScaleType(ImageView.ScaleType.CENTER_CROP); return iv; } } public String getApplicationName() { PackageManager packageManager = null; ApplicationInfo applicationInfo = null; try { packageManager = getApplicationContext().getPackageManager(); applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { applicationInfo = null; } String applicationName = (String) packageManager.getApplicationLabel(applicationInfo); return applicationName; } public void ShowMessage(String str) { new AlertDialog.Builder(this) .setTitle(getApplicationName()) .setMessage(str) .show(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.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); } }
Android 面試題及答案(2),android試題及答案1.Activity相關。launchmode,OnSaveInstnceState,生命周期等。  
android插件開發-就是你了!啟動吧!插件的activity(二) 這篇博客是上篇的延續,在閱讀之前先閱讀第一部分:第一部分 我們在啟動插件的activity時
Android開發學習之路-3DTouch效果模仿,android-3dtouch3D Touch是什麼效果的大家應該都知道了。什麼?不知道,那也沒辦法呀,我也沒有iPh
Fragment一般是宿主Activity UI的一部分或一種行為,作為Act