凌雪
2018-10-24
来源 :网络
阅读 1239
评论 0
摘要:本文将带你了解Android应用开发之记录一次android测试实例,希望本文对大家学Android有所帮助。
本文将带你了解Android应用开发之记录一次android测试实例,希望本文对大家学Android有所帮助。
记录一次android测试实例
/** * 测试进度条 */public class ProgressComponentActivity extends Activity { private LinearLayout ll_progress_loading; private ProgressBar pd_progress_loading; private SeekBar sb_progress_loading; private OnSeekBarChangeListener onSeekBarChangeListener = new OnSeekBarChangeListener() { //离开滑杆 @Override public void onStopTrackingTouch(SeekBar seekBar) { Log.e("TAG", "离开滑杆"); //1.得到SeekBar的进度 int progress = sb_progress_loading.getProgress(); //2.设置为ProgressBar的进度 pd_progress_loading.setProgress(progress); //3.判断是否达到最大值 if (progress == sb_progress_loading.getMax()) { //如果达到最大值,设置圆形进度条不可见 ll_progress_loading.setVisibility(View.INVISIBLE);//可见占用空间// ll_progress_loading.setVisibility(View.GONE);//不可见占用空间 }else{ //如果没有达到的话,设置圆形进度条显示 ll_progress_loading.setVisibility(View.VISIBLE); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { Log.e("TAG", "按下滑杆"); } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { Log.e("TAG", "滑杆移动"); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_progress_component); ll_progress_loading = (LinearLayout) findViewById(R.id.ll_progress_loading); pd_progress_loading = (ProgressBar) findViewById(R.id.pd_progress_loading); sb_progress_loading = (SeekBar) findViewById(R.id.sb_progress_loading); //给SeekBer设置监听 sb_progress_loading.setOnSeekBarChangeListener(onSeekBarChangeListener ); } } activity_progress_component.xml <LinearLayout xmlns:android="https://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:id="@+id/ll_progress_loading" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center"> <ProgressBar style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="正在加载中... ..." /> </LinearLayout> <ProgressBar android:id="@+id/pd_progress_loading" style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:progress="30"/> <SeekBar android:id="@+id/sb_progress_loading" android:layout_width="match_parent" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="功能需求:\n1.滑动下面的滑杆后,上面的进度条会同步 \n2.滑动到最大值时,最上面的进度条消失" /> </LinearLayout> //菜单Menu MenuComponentActivity.java import android.app.Activity; import android.os.Bundle;import android.view.ContextMenu;import android.view.Menu;import android.view.MenuInflater;import android.view.MenuItem;import android.view.View;import android.view.ContextMenu.ContextMenuInfo;import android.widget.Button;import android.widget.Toast;/** * 测试菜单Menu * OptionMenu * 1.如何触发Menu的显示? *点击Menu键 *2.如何向Menu中添加MenuItem? *重写onCreateOptionsMenu方法 * 1.menu.add() * 2.菜单文件 *3.选择某个MenuItem时如何响应? * 重写onOptionsItemSelected方法 * * * * 1.如何触发Menu的显示? *长按某个视图,并View.setOnCreateContextListener(this) *2.如何向Menu中添加MenuItem? *重写onCreateContextMenu()方法,用menu.add()添加,(菜单文件方式也可以) *3.选择某个MenuItem时如何响应? *重写onContextItemSelected方法,根据ItemId响应 */public class MenuComponentActivity extends Activity {private Button btn_menu_cm; @Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_menu_component); btn_menu_cm = (Button) findViewById(R.id.btn_menu_cm);//设置创建上下文菜单的监听btn_menu_cm.setOnCreateContextMenuListener(this);}//用来显示选型菜单的方法,向Menu中添加Item@Overridepublic boolean onCreateOptionsMenu(Menu menu) {//纯编码方式menu.add(0, 2, 0, "添加");menu.add(0, 3, 0, "删除");return super.onCreateOptionsMenu(menu);} // @Override// public boolean onCreateOptionsMenu(Menu menu) {// //菜单文件的方式// //1.得到菜单加载器对象// MenuInflater menuInflater = getMenuInflater();// //2.加载菜单文件// menuInflater.inflate(R.menu.option_menu, menu);// return super.onCreateOptionsMenu(menu);// } @Overridepublic boolean onOptionsItemSelected(MenuItem item) {switch (item.getItemId()) {case 2:// case R.id.add:Toast.makeText(this, "添加", Toast.LENGTH_SHORT).show();break;case 3:// case R.id.add:Toast.makeText(this, "删除", Toast.LENGTH_SHORT).show();break;}return super.onOptionsItemSelected(item);} @Overridepublic void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {super.onCreateContextMenu(menu, v, menuInfo);//添加菜单项menu.add(0,1,0,"添加");menu.add(0,2,0,"删除");} @Overridepublic boolean onContextItemSelected(MenuItem item) {switch (item.getItemId()) {case 1:Toast.makeText(this, "添加", Toast.LENGTH_SHORT).show();break;case 2:Toast.makeText(this, "删除", Toast.LENGTH_SHORT).show();break;}return super.onContextItemSelected(item);}} activity_menu_component.xml <LinearLayout xmlns:android="https://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/btn_menu_cm" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/menu_btn" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="1.点击Menu显示选项菜单\n2.长按按钮显示上下文菜单" android:textSize="30sp"/> </LinearLayout> 菜单文件方式 option_menu.xml <?xml version="1.0" encoding="utf-8"?><menu xmlns:android="https://schemas.android.com/apk/res/android" > <item android:id="@+id/add" android:title="添加2"/> <item android:id="@+id/del" android:title="删除2"/> </menu>
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之Android频道!
喜欢 | 0
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号