5
這兩者有什麼區別嗎?使用上下文獲取LayoutInflater
inflater = (LayoutInflater) LayoutInflater.from(context);
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
這兩者有什麼區別嗎?使用上下文獲取LayoutInflater
inflater = (LayoutInflater) LayoutInflater.from(context);
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
不是在現在,你可以通過檢查the LayoutInflater
source code看到。 from()
將拋出一個Exception
而不是返回null
,但否則它們是相同的。
我個人最多使用getLayoutInflater()
。