編輯:關於Android編程
現在側滑菜單使用很多,大都是通過SlidingMenu實現。現在也可以通過DrawerLayout
創建抽屜布局<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD48cD48YnIgLz48L3A+PHA+ZnJhbWVudF9jb250ZW50LnhtbDwvcD48cD48L3A+PHByZSBjbGFzcz0="brush:java;">
<frameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" > </frameLayout>
/** * ContentFragment.java * 版權所有(C) 2015 * 創建者:cuiran 2015-1-3 下午3:25:44 */ package com.cayden.drawerlayoutdemo; import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; /** * TODO * @author cuiran * @version 1.0.0 */ public class ContentFragment extends Fragment { private TextView textView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_content, container, false); textView = (TextView) view.findViewById(R.id.textView); String text = getArguments().getString("text"); textView.setText(text); return view; } }
package com.cayden.drawerlayoutdemo; import java.util.ArrayList; import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; import android.content.Intent; import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.widget.DrawerLayout; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; public class MainActivity extends Activity implements OnItemClickListener { private DrawerLayout mDrawerLayout; private ListView mDrawerList; private ArrayListmenuLists; private ArrayAdapter adapter; private ActionBarDrawerToggle mDrawerToggle; private String mTitle; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = (String) getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); menuLists = new ArrayList (); for (int i = 0; i < 5; i++) menuLists.add("菜單0" + i); adapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, menuLists); mDrawerList.setAdapter(adapter); mDrawerList.setOnItemClickListener(this); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getActionBar().setTitle("請選擇"); invalidateOptionsMenu(); // Call onPrepareOptionsMenu() } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); getActionBar().setTitle(mTitle); invalidateOptionsMenu(); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); //開啟ActionBar上APP ICON的功能 getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); } @Override public boolean onPrepareOptionsMenu(Menu menu) { boolean isDrawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); menu.findItem(R.id.action_websearch).setVisible(!isDrawerOpen); return super.onPrepareOptionsMenu(menu); } @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) { //將ActionBar上的圖標與Drawer結合起來 if (mDrawerToggle.onOptionsItemSelected(item)){ return true; } switch (item.getItemId()) { case R.id.action_websearch: Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); Uri uri = Uri.parse("http://www.baidu.com"); intent.setData(uri); startActivity(intent); break; } return super.onOptionsItemSelected(item); } @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); //需要將ActionDrawerToggle與DrawerLayout的狀態同步 //將ActionBarDrawerToggle中的drawer圖標,設置為ActionBar中的Home-Button的Icon mDrawerToggle.syncState(); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDrawerToggle.onConfigurationChanged(newConfig); } @Override public void onItemClick(AdapterView> arg0, View arg1, int position, long arg3) { // 動態插入一個Fragment到FrameLayout當中 Fragment contentFragment = new ContentFragment(); Bundle args = new Bundle(); args.putString("text", menuLists.get(position)); contentFragment.setArguments(args); FragmentManager fm = getFragmentManager(); fm.beginTransaction().replace(R.id.content_frame, contentFragment) .commit(); mDrawerLayout.closeDrawer(mDrawerList); } }
本文主要介紹使用Google自帶的FaceDetectionListener進行人臉檢測,並將檢測到的人臉用矩形框繪制出來。本文代碼基於PlayCameraV1.0.0,
之前寫過一些關於TCP和UDP數據傳輸的代碼,比如使用TCP傳輸音視頻數據包,P2P打洞中使用UDP等。寫好之後就直接丟下了,沒有總結下都。最近准備找工作,再拿來溫習下。
學習目的: 1、掌握在Android中如何建立RadioGroup和RadioButton 2、掌握RadioGroup的常用屬性 3、理解RadioButton和Che
Android系統支持原生動畫,這為應用開發者開發絢麗的界面提供了極大的方便,有時候動畫是很必要的,當你想做一個滑動的特效的時候,如果苦思冥想都搞不定,那麼你可以考慮下動