zoukankan      html  css  js  c++  java
  • 高级控件(2)

    计时器(秒表)Chronometer

    <Chronometer
       android:id="@+id/miaobiao"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"/>

     1 mychrCh.setOnChronometerTickListener(new OnChronometerTickListener(){
     2     public void onChronometerTick(Chronometer chronometer) {
     3         String time = chronometer.getText().toString().replaceAll(
     4                 "[^(\d{2}:\d{2})]", "");
     5         }
     6     });
     7     mybutton1.setOnClickListener(new OnClickListener() {
     8         public void onClick(View v) {
     9             mychrCh.start();//开始计时
    10         }
    11     });
    12     mybutton2.setOnClickListener(new OnClickListener() {
    13         public void onClick(View v) {
    14             mychrCh.stop();//停止计时
    15             tv.append(mychrCh.getText().toString()+"
    ");//追加到显示框记录时间
    16             mychrCh.setBase(SystemClock.elapsedRealtime());
    17         }
    18     });
    19 vibrator = (Vibrator)getApplication().getSystemService(Service.VIBRATOR_SERVICE);
    20 //添加震动权限
    21 vibrator.vibrate(new long[]{1000,10,1000,100},0);//
    22 vibrator.cancel();//关闭震动
    计时器

    标签页

    <第一种布局(java文件)>

    <java文件>

     1 TabHost tabHost = getTabHost();
     2     LayoutInflater.from(this).inflate(R.layout.biaoq,tabHost.getTabContentView(),true);
     3         TabSpec ts1 = tabHost.newTabSpec("tab1")
     4             .setIndicator("选项一")
     5             .setContent(R.id.ttv01);
     6         tabHost.addTab(ts1);
     7         TabSpec ts2 = tabHost.newTabSpec("tab2")
     8             .setIndicator("选项二")
     9             .setContent(R.id.ttv02);
    10         tabHost.addTab(ts2);
    11         TabSpec ts3 = tabHost.newTabSpec("tab3")
    12             .setIndicator("选项三")
    13             .setContent(R.id.ttv03);
    14         tabHost.addTab(ts3);
    标签页

    <xml>

     1 <LinearLayout
     2   xmlns:android="http://schemas.android.com/apk/res/android"
     3   android:layout_width="wrap_content"
     4   android:layout_height="wrap_content">
     5   <TextView
     6       android:id="@+id/ttv01"
     7       android:text="选项一内容:"
     8     android:layout_width="wrap_content"
     9     android:layout_height="wrap_content">
    10   </TextView>
    11   <TextView
    12       android:id="@+id/ttv02"
    13       android:text="选项二内容:"
    14     android:layout_width="wrap_content"
    15     android:layout_height="wrap_content">
    16   </TextView>
    17   <TextView
    18       android:id="@+id/ttv03"
    19       android:text="选项三内容:"
    20     android:layout_width="wrap_content"
    21     android:layout_height="wrap_content">
    22   </TextView>
    23 </LinearLayout>
    标签

     <第二种Java文件只要把ID修改>


    LayoutInflater.from(this).inflate(R.layout.biaoqtab,tabHost.getTabContentView(),true);
    .setContent(R.id.Line1);
    <xml文件>

     1 <TabHost
     2   xmlns:android="http://schemas.android.com/apk/res/android"
     3   android:orientation ="vertical"
     4   android:layout_width="fill_parent"
     5   android:layout_height="fill_parent">
     6   <LinearLayout
     7    android:orientation="vertical"
     8    android:id="@+id/Line1"
     9    android:layout_width="wrap_content"
    10    android:layout_height="wrap_content"
    11   >
    12   <TextView
    13    android:layout_width="wrap_content"
    14    android:text="是的发送到发送:"
    15    android:layout_height="wrap_content"/>
    16    <TextView
    17    android:layout_width="wrap_content"
    18    android:text="是的发送到发送到发送到:"
    19    android:layout_height="wrap_content"/>
    20   </LinearLayout>
    21   <LinearLayout
    22    android:orientation="vertical"
    23    android:id="@+id/Line3"
    24    android:layout_width="wrap_content"
    25    android:layout_height="wrap_content">
    26    <TextView
    27    android:layout_width="wrap_content"
    28    android:text="sdsdfsdfs:"
    29    android:layout_height="wrap_content"/>
    30   </LinearLayout>
    31 </TabHost>
    View Code


    注意:必须在TabHost中写

    菜单

    重写Activity中OnCreateOptionsMenu
    public boolean onCreateOptionsMenu(Menu menu) {
    //分组,菜单选项id,菜单编号,菜单标题
     menu.add(Menu.NONE,0,0,"保存");
     menu.add(Menu.NONE,1,0,"删除");
    //子菜单
     SubMenu help = menu.addSubMenu("帮助");
     help.add("保存介绍");
     help.add("出错方案");
     return super.onCreateOptionsMenu(menu);
     }
    上下级菜单
    TextView tv = (TextView)findViewById(R.id.tvv);
      registerForContextMenu(tv);
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
     ContextMenuInfo menuInfo) {
      menu.add("保存");
      menu.add("删除");
      menu.add("退出");
      super.onCreateContextMenu(menu, v, menuInfo);
    }
    (第二种方法在onCreateContextMenu修改)
    MenuInflater fInflater = getMenuInflater();
      fInflater.inflate(R.menu.main, menu);
      menu.setHeaderIcon(R.drawable.icon);
      menu.setHeaderTitle("帮助");
    Gallery
    int [] imgs = {R.drawable.icon,R.drawable.wo,R.drawable.icon,R.drawable.wo};
    Gallery gallery= (Gallery)findViewById(R.id.gallery);
    List<Map<String,Integer>> data = new ArrayList<Map<String,Integer>>();
    for(int i=0;i<imgs.length;i++){
     int img = imgs[i];
     Map<String,Integer> map = new HashMap<String, Integer>();
     map.put("img",img);
     data.add(map);
     }
    SimpleAdapter dAdapter = new SimpleAdapter(this,data,R.layout.xiala1
     ,new String[]{"img"}
     ,new int[]{R.id.IMAGE});
    gallery.setAdapter(dAdapter);
    页面
     <ImageView
       android:src="@drawable/wo"
       android:layout_width="fill_parent"
     android:layout_height="wrap_content"
      />
      <Gallery
       android:id="@+id/gallery"
       android:layout_width="fill_parent"
     android:layout_height="fill_parent"
      />
    模板
    <ImageView
       android:id="@+id/IMAGE"
       android:layout_width="fill_parent"
     android:layout_height="wrap_content"
      />

  • 相关阅读:
    把git项目放到个人服务器上
    关于fcitx无法切换输入法的问题解决
    博客变迁通知
    (欧拉回路 并查集 别犯傻逼的错了) 7:欧拉回路 OpenJudge 数据结构与算法MOOC / 第七章 图 练习题(Excercise for chapter7 graphs)
    (并查集) HDU 1856 More is better
    (并查集 不太会) HDU 1272 小希的迷宫
    (并查集 注意别再犯傻逼的错了) HDU 1213 How Many Tables
    (最小生成树 Kruskal算法) 51nod 1212 无向图最小生成树
    (并查集) HDU 1232 畅通工程
    (最小生成树 Prim) HDU 1233 还是畅通工程
  • 原文地址:https://www.cnblogs.com/luocixin/p/6944895.html
Copyright © 2011-2022 走看看