android哪些布局组件可以作为容器内部嵌套其他元素,有没有官网查看的链接

android哪些布局组件可以作为容器内部嵌套其他元素,有没有官网查看的链接

  • 你可以看下这个问题的回答https://ask.csdn.net/questions/263503
  • 这篇博客你也可以参考下:【Android 音视频开发打怪升级:音视频硬解码篇】三、音视频播放:音视频同步
  • 你还可以看下android参考手册中的 android Conference 代表一个电话会议,可以包含任何数量的连接对象。
  • 除此之外, 这篇博客: Android - 获取系统时间和网络时间中的 Android获取时间的方法有获取网络时间或者使用系统时间,两者我感觉各有优点各有缺点。 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 话不多说,直接上代码,用的话拿就好!!!

    通过网络获取时间,这是我写的一个工具类,在子线程直接调用就可以,参考一下:

    public static Date getNetTime(){
            String webUrl = "http://www.ntsc.ac.cn";//中国科学院国家授时中心
            try {
                URL url = new URL(webUrl);
                URLConnection uc = url.openConnection();
                uc.setReadTimeout(5000);
                uc.setConnectTimeout(5000);
                uc.connect();
                long correctTime = uc.getDate();
                Date date = new Date(correctTime);
                return date;
            } catch (Exception e) {
                return new Date();
            }
        }
    
    获取本地系统时间代码:
    long time = System.currentTimeMillis();
    Date date = new Date(time);
    SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 E HH时mm分ss秒");
    main_date.setText(format.format(date));

    全部代码:

    package com.djp.test.test2;
    
    import android.graphics.Bitmap;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.support.v7.app.AppCompatActivity;
    import android.widget.TextView;
    import android.widget.Toast;
    
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    /**
     * 一般耗时操作都不允许放在主线程里直接操作,如网络操作等,
     * 一般需要开一个子线程去访问网络,然后通过handler去更新界面。
     * 显示例如2019年02月22日  周五  14时56分08秒
     */
    //温度  多云转晴  南风3-4级
    public class TwoActivity extends AppCompatActivity {
        private  TextView textView;
    
        private Handler handler = new Handler(){
            //此方法在主线程中使用,用于刷新UI
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switch (msg.what){
                    case 1:
                        /*long time = System.currentTimeMillis();
                        Date date = new Date(time);
                        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 E HH时mm分ss秒");
                        main_date.setText(format.format(date));*/
    
    
    
                      // textView.setText(new SimpleDateFormat("yyyy年MM月dd日 E HH时mm分ss秒").format(new Date(System.currentTimeMillis())));//获取系统时间
    
                        textView.setText(new SimpleDateFormat("yyyy年MM月dd日 E HH时mm分ss秒").format(msg.obj));//获取网络时间
                        break;
    
                }
            }
        };
    
        /**
         * 获取当前时间
         * @return
         */
        public static Date getNetTime(){
            //设置了超时时长为5秒,若获取网络时间在5秒内无法获取,则返回本机时间。
            String webUrl = "http://www.ntsc.ac.cn";//中国科学院国家授时中心
            try {
                URL url = new URL(webUrl);
                URLConnection uc = url.openConnection();//生成连接对象
                uc.setReadTimeout(5000);
                uc.setConnectTimeout(5000);
                uc.connect();//发出连接
                long correctTime = uc.getDate();//取得网站日期时间
                Date date = new Date(correctTime);
                return date;
            } catch (Exception e) {
                return new Date();
            }
        }
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_two);
            textView = findViewById(R.id.textview1);
            new TimeThread().start();//启动线程
        }
        public class TimeThread extends Thread {
            @Override
            public void run() {
                super.run();
                do {
                    try {
                        Thread.sleep(1000);
    
    
                        Message msg = new Message();
                        msg.what = 1;
                        //调用获取时间
                        msg.obj= getNetTime();
    
                        handler.sendMessage(msg);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        e.printStackTrace();
                    }
                } while (true);
            }
    
    
        }
    }
    

     

  • 您还可以看一下 刘桂林老师的Android仿网易云音乐播放器课程中的 彻底解决音乐卡顿的解码问题小节, 巩固相关知识点