亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Android基于基于布局嵌套的頁面導(dǎo)航實現(xiàn)

系統(tǒng) 1830 0

?

?頁面如下:

Android基于基于布局嵌套的頁面導(dǎo)航實現(xiàn)

?

?

?

?

?

?

主頁面的布局分隔為三部分:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gztab_content"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="
    
      vertical
    
    " >
  <!-- header  -->
 
    
      <include android:id="@+id/gz_top" layout="@layout/gzmgr_top_panel" android:layout_width="fill_parent"
       android:layout_height="wrap_content"/>
    
    
  <!-- content  -->
  
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    
    
      android:id="@android:id/tabhost"
    
    
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id
    
      ="@android:id/tabs"
    
    
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
        </TabWidget>

        <FrameLayout
            android:id
    
      ="@android:id/tabcontent"
    
    
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

          <LinearLayout 
			    android:layout_width="fill_parent"
			    android:layout_height="fill_parent"
			    android:orientation="vertical" 
			    android:id
    
      ="@+id/unhanlderLayout
    
    ">
			           <Button android:id="@+id/gzbtn_unhandler_refresh" 
			               android:layout_width="fill_parent"
			               android:layout_height="wrap_content"
			               android:text="刷新"
			               />
					  <LinearLayout 
					    android:layout_width="fill_parent"
					    android:layout_height="fill_parent"
					    android:orientation="vertical" >
					     <ListView android:id="@+id/gz_unhandler_ListView"
					         android:layout_width="fill_parent"
					         android:layout_height="wrap_content">
					     </ListView>
					  </LinearLayout>
			  </LinearLayout>

             <LinearLayout 
			    android:layout_width="fill_parent"
			    android:layout_height="fill_parent"
			    android:orientation="vertical" 
				android:id
    
      ="@+id/handlingLayout">
    
    
			           <Button android:id="@+id/gzbtn_handlering_refresh" 
			               android:layout_width="fill_parent"
			               android:layout_height="wrap_content"
			               android:text="刷新"
			               />
					  <LinearLayout 
					    android:layout_width="fill_parent"
					    android:layout_height="fill_parent"
					    android:orientation="vertical" >
					     <ListView android:id="@+id/gz_handleringListView"
					         android:layout_width="fill_parent"
					         android:layout_height="wrap_content">
					     </ListView>
					  </LinearLayout>
			  </LinearLayout>

            <LinearLayout 
			    android:layout_width="fill_parent"
			    android:layout_height="fill_parent"
			    android:orientation="vertical" 
			    android:id
    
      ="@+id/handledLayout">
    
    
			           <Button android:id="@+id/gzbtn_handled_refresh" 
			               android:layout_width="fill_parent"
			               android:layout_height="wrap_content"
			               android:text="刷新"
			               />
					  <LinearLayout 
					    android:layout_width="fill_parent"
					    android:layout_height="fill_parent"
					    android:orientation="vertical" >
					     <ListView android:id="@+id/gzgzbtn_handled_ListView"
					         android:layout_width="fill_parent"
					         android:layout_height="wrap_content">
					     </ListView>
					  </LinearLayout>
			  </LinearLayout>
        </FrameLayout>
    </LinearLayout>
</TabHost>
  <!-- bottom  -->

    
        <Button android:id="@+id/btnManyInfo" android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="更多(10)"/>
    
    
</LinearLayout>
  

?

注意觀察上面標記為紅色的android:id均采用android系統(tǒng)默認的名稱:

?

頁面的導(dǎo)航組件:

    <?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout  android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android">
    <Button 
        android:id="@+id/top_gzbtn_left" 
         
    
      android:text="返回"
    
     
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="12.0dip" 
         
    
      android:layout_alignParentLeft="true"
    
    
      android:layout_centerVertical="true"
    
     />
    <Button 
         android:id="@+id/top_gzbtn_right" 
         
    
      android:text="發(fā)布"
    
     
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_marginRight="12.0dip" 
         
    
      android:layout_alignParentRight="true
    
    " 
         
    
      android:layout_centerVertical="true
    
    " />
    <TextView android:textSize="22.0sp" 
         android:textColor="#ffffffff"
          android:ellipsize="middle"
           android:gravity="center_horizontal" 
           android:id="@+id/top_gztxt_title"
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           
    
      android:text="故障管理
    
    " 
    
      android:singleLine="true"
    
    
      android:layout_toLeftOf="@+id/top_gzbtn_right"
    
    
      android:layout_toRightOf="@+id/top_btn_left0"
    
    
      android:layout_centerInParent="true"
    
     android:layout_alignWithParentIfMissing="true" >
        </TextView>
</RelativeLayout>
  

?

上面紅色布局主要采用相對布局定位相關(guān)的導(dǎo)航位置:

?

?

每一個tab頁面的中的內(nèi)容如下:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <!-- 個人信息 -->
    <LinearLayout android:id="@+id/gzPersonInfoLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >
	    <ImageView  android:id="@+id/gzimg_item_Img"
	        android:layout_width="wrap_content"
	        android:layout_height="wrap_content"
	        android:layout_margin="5px"
	        android:layout_gravity="left"
	        android:src="@drawable/ic_launcher"/>
	    <TableLayout android:layout_width="fill_parent"
	        android:layout_height="fill_parent"
	        android:shrinkColumns="1"
	        android:layout_gravity="right"
	        >
	        <TableRow >
	              <TextView   android:id="@+id/gztxt_item_userCode"                      android:padding="3dip"  />         
	              <TextView   android:id="@+id/gztxt_item_UserCollectionName"          android:padding="3dip"  />         
	              <TextView   android:id="@+id/gztxt_item_Time"                       android:padding="3dip"  /> 
	        </TableRow>
	        <TableRow >
	              <TextView    android:id="@+id/gztxt_item_name_person"                       android:padding="3dip"  />         
	              <TextView                android:text=""             android:padding="3dip"  />         
	              <TextView                     android:padding="3dip"  /> 
	        </TableRow>
	    </TableLayout>
	</LinearLayout>
    <LinearLayout 
            android:id="@+id/gzItemLayout"
		    android:layout_width="fill_parent"
		    android:layout_height="fill_parent"
		    android:orientation="horizontal" >
	            <TableLayout   
				     android:layout_width="fill_parent"     
				     android:layout_height="fill_parent" >
				       <TableRow>         
				           <TextView             android:text="項目名稱:"             android:padding="3dip" />         
				           <TextView     android:id="@+id/gztxt_item_name"                      android:padding="3dip" />         
				           <TextView             android:text="列車編號:"             android:padding="3dip"  />     
				           <TextView             android:id="@+id/gztxt_item_code"             android:padding="3dip"  />     
				       </TableRow> 
				</TableLayout>
	 </LinearLayout>
	   <LinearLayout 
	            android:id="@+id/gzItemLayout"
			    android:layout_width="fill_parent"
			    android:layout_height="fill_parent"
			    android:orientation="horizontal" >
			         <TableLayout android:layout_width="fill_parent"
			        android:layout_height="fill_parent"
			        android:shrinkColumns="1"
			        android:layout_gravity="right"
			        >
			        <TableRow >
			              <TextView           android:text="故障負責(zé)人"             android:padding="3dip"  />         
			              <TextView   android:id="@+id/gztxt_item_user"            android:padding="3dip"  />         
			        </TableRow>
			        <TableRow >
			              <TextView             android:text="故障處理人"             android:padding="3dip"  />         
			              <TextView      android:id="@+id/gztxt_item_handler"                        android:padding="3dip"  />         
			        </TableRow>
			                <TableRow >
			              <TextView               android:text="故障描述"             android:padding="3dip"  />         
			              <TextView      android:id="@+id/gztxt_item_descption"      android:padding="3dip"  />         
			        </TableRow>
			         <TableRow >
			              <TextView              android:text="問題級別:"             android:padding="3dip"  />         
			              <TextView     android:id="@+id/gztxt_item_level"            android:text="一般"             android:padding="3dip"  />         
			        </TableRow>
			           <TableRow >
			              <TextView             android:text="狀態(tài):"             android:padding="3dip"  />         
			              <TextView      android:id="@+id/gztxt_item_status"              android:text="未解決"             android:padding="3dip"  />         
			        </TableRow>
			    </TableLayout>
	   </LinearLayout>
</LinearLayout>
  

?

?

?

?

訊飛的語音sdk是需要申請的,地址是: http://dev.voicecloud.cn/developer.php?vt=1 ?。申請一個訊飛的開發(fā)者賬號,然后申請一個appid,申請的時候需要填寫開發(fā)者信息和你的應(yīng)用的信息。

申請之后經(jīng)過審核通過,會得到一個appid,這個是在使用語音服務(wù)時需要用到的。(筆者感覺申請還是比較容易通過的,簡單地填寫一下就通過了。速度也很快,我在晚上十一點多申請的,到第二天早上九點多就收到審核通過的郵件。個人感覺這個審核只是為了防止惡意使用,畢竟語音服務(wù)是要使用訊飛的服務(wù)器資源的。)

申請到appid之后就可以下載SDK了,然后使用語音服務(wù)了。


以下我試用的過程,(點擊button,彈出語音框,說完之后將識別的結(jié)果顯示在EditText中 ):

?

  • 在eclipse里新建一個android工程
  • å°Ž(dÇŽo)入訊飛的語音jar包
  • 訊飛的服務(wù)是需要一堆權(quán)限的,在manifest.xml中加入
    1. < uses-permission ? android:name = "android.permission.RECORD_AUDIO" ? /> ??
    2. < uses-permission ? android:name = "android.permission.INTERNET" ? /> ??
    3. < uses-permission ? android:name = "android.permission.ACCESS_NETWORK_STATE" ? /> ??
    4. < uses-permission ? android:name = "android.permission.ACCESS_WIFI_STATE" ? /> ??
    5. < uses-permission ? android:name = "android.permission.CHANGE_NETWORK_STATE" ? /> ??
    6. < uses-permission ? android:name = "android.permission.READ_PHONE_STATE" ? /> ??
                <uses-permission android:name="android.permission.RECORD_AUDIO" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
          
    分別為:通過麥克風(fēng)錄音、聯(lián)網(wǎng)、獲取網(wǎng)絡(luò)信息狀態(tài)、獲取wifi狀態(tài)、改變網(wǎng)絡(luò)狀態(tài)如是否能聯(lián)網(wǎng)、訪問電話狀態(tài)
  • 在main.xml中添加一個EditText和一個Button,如下
    1. <? xml ? version = "1.0" ? encoding = "utf-8" ?> ??
    2. < LinearLayout ? xmlns:android = "http://schemas.android.com/apk/res/android" ??
    3. ???? android:layout_width = "fill_parent" ??
    4. ???? android:layout_height = "fill_parent" ??
    5. ???? android:orientation = "vertical" ? > ??
    6. ??
    7. ???? < EditText ??
    8. ???????? android:id = "@+id/editText" ??
    9. ???????? android:layout_width = "fill_parent" ??
    10. ???????? android:layout_height = "300dp" ??
    11. ???????? android:gravity = "top" ??
    12. ???????? android:inputType = "textMultiLine" ? > ??
    13. ??
    14. ???????? < requestFocus ? /> ??
    15. ???? </ EditText > ??
    16. ??
    17. ???? < Button ??
    18. ???????? android:id = "@+id/button_start" ??
    19. ???????? android:layout_width = "wrap_content" ??
    20. ???????? android:layout_height = "wrap_content" ??
    21. ???????? android:text = "點擊開始說話" ? /> ??
    22. ??
    23. </ LinearLayout > ??
            <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <EditText
            android:id="@+id/editText"
            android:layout_width="fill_parent"
            android:layout_height="300dp"
            android:gravity="top"
            android:inputType="textMultiLine" >
    
            <requestFocus />
        </EditText>
    
        <Button
            android:id="@+id/button_start"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="點擊開始說話" />
    
    </LinearLayout>
          
  • 然后在MainActivity中編寫代碼實現(xiàn)了

?

(這里可以看到在線的文檔: http://dev.voicecloud.cn/developer.php?category=YW5kcm9pZA%3D%3D&column=ZG9jdW1lbnQ%3D&type=d2lkZ2V0 )

通過閱讀訊飛給的文檔,可以發(fā)現(xiàn)標準的識別控件是RecognizerDialog——是一個Dialog的子類,所以我們是可以在Activity中通過showDialog(int)方法來調(diào)用它的。

重寫Activity的方法

  1. @Override ??
  2. protected ?Dialog?onCreateDialog( int ?id)?{}??
    	@Override
	protected Dialog onCreateDialog(int id) {}
  

在其中創(chuàng)建并設(shè)置好一個RecognizerDialog即可。

?


創(chuàng)建 RecognizerDialog 方法為

  1. RecognizerDialog?recognizerDialog?=? new ?RecognizerDialog(??
  2. ????????MainActivity. this ,? "appid=1234567" ); //?這里應(yīng)該寫從科大訊飛申請到的appid ??
    		RecognizerDialog recognizerDialog = new RecognizerDialog(
				MainActivity.this, "appid=1234567");// 這里應(yīng)該寫從科大訊飛申請到的appid
  

(其中appid應(yīng)該寫自己從訊飛申請到的appid,由于協(xié)議的問題,我不便把自己申請的id公開,所以這里用了1234567來代替。根據(jù)訊飛的說明,非法的appid是不能使用語音服務(wù)的,但是我用隨機數(shù)字試驗了一下,居然也是能用的,不知道是不是BUG。)

?

? ? ? ? ? ? ? ? ? ? ? ? ? 官方的文檔:

? ? ? ?

然后需要設(shè)置識別參數(shù)

  1. recognizerDialog.setEngine( "sms" ,? null ,? null );??
    		recognizerDialog.setEngine("sms", null, null);
  

第一個參數(shù)“sms”表示為請求的服務(wù)為“語音識別”。后兩個參數(shù)暫時設(shè)為null就好。

?

? ? ? ? ? ? ?官方文檔:


最后還需給recognizerDialog設(shè)置一個listener,回調(diào)接口用以獲取結(jié)果,

recognizerDialog.setListener(RecognizerDialogListener listener)的參數(shù)為RecognizerDialogListener接口,實現(xiàn)此接口要重寫兩個方法:onResults(ArrayList results,boolean isLast)和onEnd(SpeechError error)。用以獲取和處理結(jié)果。

我的實現(xiàn)為直接寫了一個匿名類:

  1. recognizerDialog.setListener( new ?RecognizerDialogListener()?{??
  2. ???? @Override ??
  3. ???? public ? void ?onResults(ArrayList<RecognizerResult>?results,??
  4. ???????????? boolean ?arg1)?{??
  5. ????????StringBuffer?result?=? new ?StringBuffer();??
  6. ???????? for ?(RecognizerResult?r?:?results)?{??
  7. ????????????result.append(r.text);??
  8. ????????}??
  9. ????????editText.setText(result.toString());??
  10. ????}??
  11. ??
  12. ???? @Override ??
  13. ???? public ? void ?onEnd(SpeechError?arg0)?{??
  14. ??
  15. ????}??
  16. });??
    		recognizerDialog.setListener(new RecognizerDialogListener() {
			@Override
			public void onResults(ArrayList<RecognizerResult> results,
					boolean arg1) {
				StringBuffer result = new StringBuffer();
				for (RecognizerResult r : results) {
					result.append(r.text);
				}
				editText.setText(result.toString());
			}

			@Override
			public void onEnd(SpeechError arg0) {

			}
		});
  

然后將此RecognizerDialog返回即可。

?


完整的MainActivity代碼:

?

  1. import ?com.iflytek.speech.RecognizerResult;??
  2. import ?com.iflytek.speech.SpeechError;??
  3. import ?com.iflytek.ui.RecognizerDialog;??
  4. import ?com.iflytek.ui.RecognizerDialogListener;??
  5. ??
  6. public ? class ?MainActivity? extends ?Activity?{??
  7. ??
  8. ????EditText?editText?=? null ;??
  9. ????Button?startButton?=? null ;??
  10. ??
  11. ???? @Override ??
  12. ???? public ? void ?onCreate(Bundle?savedInstanceState)?{??
  13. ???????? super .onCreate(savedInstanceState);??
  14. ????????setContentView(R.layout.main);??
  15. ????????editText?=?(EditText)?findViewById(R.id.editText);??
  16. ????????startButton?=?(Button)?findViewById(R.id.button_start);??
  17. ????????startButton.setOnClickListener( new ?OnClickListener()?{??
  18. ???????????? @Override ??
  19. ???????????? public ? void ?onClick(View?v)?{??
  20. ????????????????showDialog( 1 );??
  21. ????????????}??
  22. ????????});??
  23. ????}??
  24. ??
  25. ???? @Override ??
  26. ???? protected ?Dialog?onCreateDialog( int ?id)?{??
  27. ????????RecognizerDialog?recognizerDialog?=? new ?RecognizerDialog(??
  28. ????????????????MainActivity. this ,? "appid=1234567" ); //?這里應(yīng)該寫從科大訊飛申請到的appid ??
  29. ????????recognizerDialog.setEngine( "sms" ,? null ,? null );??
  30. ????????recognizerDialog.setListener( new ?RecognizerDialogListener()?{??
  31. ???????????? @Override ??
  32. ???????????? public ? void ?onResults(ArrayList<RecognizerResult>?results,??
  33. ???????????????????? boolean ?arg1)?{??
  34. ????????????????StringBuffer?result?=? new ?StringBuffer();??
  35. ???????????????? for ?(RecognizerResult?r?:?results)?{??
  36. ????????????????????result.append(r.text);??
  37. ????????????????}??
  38. ????????????????editText.setText(result.toString());??
  39. ????????????}??
  40. ??
  41. ???????????? @Override ??
  42. ???????????? public ? void ?onEnd(SpeechError?arg0)?{??
  43. ??
  44. ????????????}??
  45. ????????});??
  46. ???????? return ?recognizerDialog;??
  47. ????}??
  48. }??
    import com.iflytek.speech.RecognizerResult;
import com.iflytek.speech.SpeechError;
import com.iflytek.ui.RecognizerDialog;
import com.iflytek.ui.RecognizerDialogListener;

public class MainActivity extends Activity {

	EditText editText = null;
	Button startButton = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		editText = (EditText) findViewById(R.id.editText);
		startButton = (Button) findViewById(R.id.button_start);
		startButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				showDialog(1);
			}
		});
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		RecognizerDialog recognizerDialog = new RecognizerDialog(
				MainActivity.this, "appid=1234567");// 這里應(yīng)該寫從科大訊飛申請到的appid
		recognizerDialog.setEngine("sms", null, null);
		recognizerDialog.setListener(new RecognizerDialogListener() {
			@Override
			public void onResults(ArrayList<RecognizerResult> results,
					boolean arg1) {
				StringBuffer result = new StringBuffer();
				for (RecognizerResult r : results) {
					result.append(r.text);
				}
				editText.setText(result.toString());
			}

			@Override
			public void onEnd(SpeechError arg0) {

			}
		});
		return recognizerDialog;
	}
}
  


程序在真機運行截圖,經(jīng)過檢驗,科大訊飛的識別率還是很高的。? ??

?

demo下載地址: http://download.csdn.net/detail/barryhappy/4178459


Android基于基于布局嵌套的頁面導(dǎo)航實現(xiàn)


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】元

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲爽爽| 欧美在线色 | 日韩久久精品一区二区三区 | 五月婷中文字幕 | 日本高清影院 | 操一操干一干 | 亚洲爱婷婷色婷婷五月 | 精品成人免费视频 | 久久夜色视频 | 亚洲精品影院 | 一级特级女人18毛片免费视频 | 曰批免费视频播放在线看片二 | 国产精品久久久久久五月尺 | 在线观看欧美亚洲日本专区 | 国产末成年女av片 | 多色视频| 国产成人精品日本亚洲专一区 | 亚洲精品一区二区三区在线观看 | 在线欧美精品一区二区三区 | 最新亚洲精品国自产在线 | 亚洲欧美精品日韩欧美 | 91国视频在线观看 | 日韩精品中文字幕在线 | 国产一级特黄高清免费大片 | 特级黄色视频毛片 | 中文字幕一区在线播放 | 日日操操干干 | 成人淫片 | 久久天天躁夜夜躁狠狠躁2020 | 日韩精品成人免费观看 | 亚洲欧美色综合自拍 | 黄色毛片免费在线观看 | 五月天婷亚洲天综合网精品偷 | 亚洲水蜜桃久久综合网站 | 九九自拍 | 五月婷婷婷婷婷 | 奇米影视第四色首页 | 大杳蕉伊人狼人久久一本线 | 亚洲国产成人99精品激情在线 | 亚洲欧美综合一区 | 视频二区 中文字幕 欧美 |