public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  LinearLayout ll = (LinearLayout) findViewById(R.id.layInfo);
 Log.i("w", ll.getWidth()+"L"+ll.getHeight());

你会发现打印出来是0

那是因为在onCreate方法的时候LinearLayout还并没有绘制完成,所以获取的高度均为0,

或者试着把这段代码放到onResume()方法中去,依然是0。

如果我们用获取LinearLayout的宽高

可以通过定时器不断的监听LinearLayout的宽高,等绘制完成后,关闭定时器即可。

private  LinearLayout ll ;
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  LinearLayout ll = (LinearLayout) findViewById(R.id.layInfo);
timer.schedule(task,10,1000); 
}
final Handler handler= new Handler(){
   @Override
   public void handleMessage(Message msg) {
   if(msg.what == 1) {
    if(ll.getWidth()!=0) {
    Log.i("w", ll.getWidth()+"L"+ll.getHeight());
      timer.cancel();
  timer = new Timer();
  TimerTask task = new TimerTask(){
   public void run() { 
    Message message = new Message(); 
    message.what = 1; 
    myHandler.sendMessage(message); 

类似,如果想在Activity启动后立即弹出PopupWindow,我们知道在Activity的onCreate()方法中直接写弹出PopupWindow方法会报错,因为activity没有完全启动是不能弹出PopupWindow

我们可以尝试用两种方法实现:

1、用onWindowFocusChanged方法

@Override
public void onWindowFocusChanged(boolean hasFocus) {
 super.onWindowFocusChanged(hasFocus);
 showPopupWindow();

2、用HandlerRunnable,延时

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 mHandler.postDelayed(mRunnable, 1000);
private Runnable mRunnable = new Runnable() {
 public void run() {
 showPopupWindow();

这样获取LinearLayout宽高问题就解决了。

python 查看 shape python 查看对象的所有属性

文章目录Python 查看对象方法和属性简介办法dir函数通过制定对象类型 Python 查看对象方法和属性简介PyCharm使用对象.的方式无法显示对象的属性和方法,可是对API又不熟悉,那咋办呢?办法dir函数通过dir(obj)函数,获取obj的所有方法和属性。打印urllib3所有的方法和属性import urllib3 print(dir(urllib3))打印['HTTPConnec

操作型数据库 数据仓库 操作数据库的类有几种

对数据库的操作可以分为四类:DDL:操作数据库,表等DML:对表中的数据进行增删改DQL:对表中的数据进行查询DCL:对数据库进行权限控制除此以外,数据库的数据模型如下:DDL操作数据库show databases; -- 查询数据库 create database 数据库名称; -- 创建数据库 create database if not exists 数据库名称; -- 如果数据库不存在