Android Studio - ãµã³ãã«ããã¸ã§ã¯ããèªãã§ã¿ã
MainActivity
ActionBarActivityãç¶æ¿ãã¦ããã
ActionBarã¯Androidã¢ããªã®ä¸é¨ã«ã¤ãã¦ãããã²ã¼ã·ã§ã³ãã¼ã®ãã¨ãæ¨æºã®ãµãã¼ãã©ã¤ãã©ãªã«å«ã¾ãã¦ããã
android.support.v7.app | Android Developers
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.container, new PlaceholderFragment()) .commit(); } }
Bundle savedInstanceState
ã¨ã¯ãã¢ããªçµäºæã®ç¶æ
ãä¿åãã¦ãããã®ããªã®ã§ãã®ifç¯ã§ã¯ãååèµ·åæã«ã©ããããã¨ããå¦çããã¦ããã
ï¼ååèµ·åæã ããããªãã¦ãä½ãä»ã®æã«ãå
¥ããã/æªç¢ºèªï¼
getSupportFragmentManager()
ã¯ãç¾å¨ã®Activityã«é¢é£ããFragmentManagerãåå¾ãããã®ã
FragmentActivity | Android Developers
ããã§åå¾ããMangaerã使ã£ã¦ããã©ã³ã¶ã¯ã·ã§ã³ãéå§ããPlaceHolderFragmentã¨ãããã©ã°ã¡ã³ããR.id.container
ã¨ããidã§å®ç¾©ãããlayoutã«ç´ä»ããã
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" tools:ignore="MergeRootFrame" />
layoutãã¡ã¤ã«ã®tools:context
ã¨ã¯ãªãããï¼ï¼
xml - What's "tools:context" in Android layout files? - Stack Overflow
StackOverflowã«ããã¨ãUIã¨ãã£ã¿ãã¬ã¤ã¢ã¦ããã¬ã³ããªã³ã°ããã¨ãã«ä½¿ãActivityã¨ãããã¨ã§â¦ããã¨é£åãã¦ããã¿ããâ
Activityã ãã§ãªãFragmentãæå®ãããã¨ãåºæ¥ãã
fragment_main.xml
tools:context=".MainActivity$PlaceholderFragment
tools:ignore
ã§ã¯Android Lintãé¨åçã«ç¡è¦ããè¨å®ããã¦ããã
AndroidLintã«ã¤ãã¦ã®èª¬æã¯ãã¡ãã詳ããã
Android Lint の利用方法を記載 | Bescottee
lintã¨ã¯ãããã湿å¸ã«ä½¿ããã¦ãããããªãµããµãèµ·æ¯ããå¸ã¨ã綿ããã®ãã¨ãè¨ãããããã§ãCè¨èªã«ã¯
lintã¨ã¯ã主ã«Cè¨èªã®ã½ã¼ã¹ã³ã¼ãã«å¯¾ããã³ã³ãã¤ã©ãã詳細ãã¤å³å¯ãªãã§ãã¯ãè¡ãããã°ã©ã ã§ããã
ã¨ãããã®ããããfree lintï¼ç³¸ãããåºãªãï¼ã£ã¦è¨èãã転ãã¦ãå ããªç¶»ã³ããªãã³ã¼ãâ¦ã¨ããæå³ã«ãªã£ããã¯ç¥ããªããã©ï¼ãã¿ã¾ããæãã¤ãã§è¨ã£ã¦ãã¾ãï¼ãã¨ã«ããlintã¯ã¡ãã£ã¨ãããã¹ãææãã¦ããããã¤ã§ããä¾ãã°html lintãªãéãã¿ã°ã足ããªããï¼ã¨ãè¨ã£ã¦ããã¾ãã
ã§ãAndroid Lintãåæ§ã«ç´°ããªãã§ãã¯ããã¦ãããããã§ãããã¯ADT16ï¼2011å¹´12æçï¼ãã追å ãããæ©è½ã®ããã§ãã
lintãä½ããã§ãã¯ãã¦ãããã¯ä»¥ä¸ã§è¦ãã¾ãã
http://tools.android.com/tips/lint-checks
ç®ã«ã¤ãããã®ãæç²ãã¦ã¿ãã¨â¦
- NewApi: Finds API accesses to APIs that are not supported in all targeted API versions
- ShowToast: Looks for code creating a Toast but forgetting to call show() on it
- Toastä½ã£ã¦ããã©showãã¦ããªãï¼ç¢ºãã«ããæ¸ãå¿ããããããâ¦ï¼
- Deprecated: Looks for usages of deprecated layouts, attributes, and so on.
- éæ¨å¥¨ãªã¬ã¤ã¢ã¦ãã¨ãå±æ§ã¨ãã使ã£ã¦ãã
ãªã©ãªã©ãè²ã ããã¾ããã
ãã¦ãç¥ãããã£ãMergeRootFrameã¯ã©ããªãã¤ãªã®ãã¨ããã¨
MergeRootFrame
Summary: Checks whether a root <FrameLayout> can be replaced with a <merge> tag
Priority: 4 / 10 Severity: Warning Category: Performance
If a <FrameLayout> is the root of a layout and does not provide background or padding etc, it can often be replaced with atag which is slightly more efficient. Note that this depends on context, so make sure you understand how the <merge> tag works before proceeding.
More information: Android Layout Tricks #3: Optimize by merging | Android Developers Blog <<
åã£ã¦ããåãããªããã©è¨³ãã¦ã¿ãã¨â¦
ã«ã¼ãã®FrameLayoutã<merge>ã¿ã°ã§ç½®æããã¦ãããã©ãããã§ãã¯ããã ããFrameLayoutãã¬ã¤ã¢ã¦ãã®ã«ã¼ãã§ãèæ¯ãpaddingãæä¾ããªããªããmergeã¿ã°ã«ç½®æãããã¨ã§å°ãå¹ççã«ã§ãã¾ããããã¯ç¶æ³æ¬¡ç¬¬ãªã®ã§ãmergeã¿ã°ãã©ã®ãããªåããããã®ãã¡ããã¨ç解ãã¦ãã ãããã
â¦ã¨ããæãï¼
Android Layout Tricks #3: Optimize by merging | Android Developers Blog
mergeã¿ã°ã使ãã¨ã¬ã¤ã¢ã¦ãã®é層ãæ·±ããªãã®ãæãããã¨ãã§ãã¾ãã
hierarchy viewerã§å®éã«ç¢ºèªãã¦ã¿ããã¨æã£ãã®ã§ãããAndroid Studioã®ã©ãã«ããã®ãè¦ã¤ããããªãâ¦orz
æ¢ãã¾ãã£ã¦ããããæ£ã¼ãçã«ãPreferences->Inspections->Android Lintã§ã©ã®Lintãæ¤ç¥ãã¦ã©ãã¯ç¡è¦ããã®ããèªç±ã«è¨å®ã§ãããã¨ãåããã¾ããã
話ã大ããæ»ãã¦ãPlaceholderFragmentã§ãããMainActivityã®ä¸ã®æ¹ã«å®ç¾©ããã¦ãã¾ããã
/** * A placeholder fragment containing a simple view. */ public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); return rootView; } }
Fragmentã¯ãµãã¼ãã©ã¤ãã©ãªï¼v4ï¼ã§å®ç¾©ããã¦ããæ©è½ã§ãActivityã¨ã¬ã¤ã¢ã¦ãã®éãåãæã¤ãã®ã¨ããã¤ã¡ã¼ã¸ã§â¦ããã®ããªâ¦ã
Activityã§ç´æ¥ã¬ã¤ã¢ã¦ãã¨ãã¸ãã¯ã管çããã¨ã1ã¤ã®ç»é¢ã«è¤æ°ã®æ©è½ãå«ã¾ããã¨ãã«å¤§å¤ãä¾ãã°fbã®å·¦ããã¹ã©ã¤ããã¦åºã¦ããã¡ãã¥ã¼ç»é¢ã¨ããããã¼ã¨ãã³ã³ãã³ãé¨åãªããã¯ããããã®ã¬ã¤ã¢ã¦ãã«ããããããã¸ãã¯ããã£ã¤ããæãã§æ±ããæ¹ã便å©ã§ããç¹ã«Androidã®å ´åç»é¢ã大ãã端æ«ãå¤ãã£ããããã®ã§ã横ã¬ã¤ã¢ã¦ãã®æã«ã¯å·¦ã®ã¡ãã¥ã¼ãåºãã£ã±ãªãã«ããããã¨ãããå ´åã«ããã¸ãã¯ã¯åããã®ã使ãåããã®ã§Fragmentã¯ä¾¿å©ã§ãã
â¦â¦ã£ã¦ãã¨ããã®æ¬ã«è¼ã£ã¦ã¾ããããã£ã¨æ£ããåãããããæ¸ãã¦ããã®ã§è©³ããã¯ãã¡ããåç §ã§ã
Android UI Cookbook for 4.0 ICSï¼Ice Cream Sandwichï¼ã¢ããªéçºè¡
- ä½è : ãããããã
- åºç社/ã¡ã¼ã«ã¼: ã¤ã³ãã¬ã¹ã¸ã£ãã³
- çºå£²æ¥: 2012/03/16
- ã¡ãã£ã¢: åè¡æ¬ï¼ã½ããã«ãã¼ï¼
- è³¼å ¥: 2人 ã¯ãªãã¯: 47å
- ãã®ååãå«ãããã° (18件) ãè¦ã
Fragmentã®ä¸ã«ãã©ã¤ããµã¤ã¯ã«ãããã¾ãã
Fragmentを動的に変化させる « Tech Booster
onCreateViewã¯Fragmentã«é¢é£ä»ããViewãè¿ãã¾ãã
View rootView = inflater.inflate(R.layout.fragment_main, container, false); return rootView;
ããã§container
ã«ã¯activity_main.xmlã§å®ç¾©ããã¦ããFrameLayoutï¼ã¤ã¾ãActivityå
¨ä½ã®å¤§æ ã®ã¬ã¤ã¢ã¦ãï¼ãå
¥ãã¾ãã
http://y-anz-m.blogspot.jp/2012/04/android-viewgroup.html
ãªã®ã§ãrootView
ããããã°ãã¦è¦ã¦ã¿ãã¨ãandroid.widget.RelativeLayout
ï¼fragment_main.xmlã§å®ç¾©ããã¦ãã大æ ï¼ã«ãªã£ã¦ãã¾ãã
è¦ã¯ã第ä¸å¼æ°ãtrueãªãã第äºå¼æ°ãè¿ãã第ä¸å¼æ°ãfalseãªã第ä¸å¼æ°ã®ã«ã¼ãã¬ã¤ã¢ã¦ããè¿ãããã ãã第äºå¼æ°ãnullã®å ´åã«ã¯ç¬¬ä¸å¼æ°ã®ã«ã¼ãã¬ã¤ã¢ã¦ããè¿ããâ¦ã®ããªâ¦ã
ã¡ãã£ã¨ãã®è¾ºãã¯è¦åå¼·ã¨ããæãããã¾ãã
ä¸æ¦ããã¾ã§ã