Is a RelativeLayout more expensive than a LinearLayout?

In a talk at Google I/O 2013 (Writing Custom Views for Android), Romain Guy clarified the misunderstanding that caused everyone to start using RelativeLayouts for everything. A RelativeLayout always has to do two measure passes. Overall it is negligible as long as your view hierarchy is simple. But if your hierarchy is complex, doing an … Read more

Android LinearLayout : Add border with shadow around a LinearLayout

Try this.. <?xml version=”1.0″ encoding=”utf-8″?> <layer-list xmlns:android=”http://schemas.android.com/apk/res/android”> <item> <shape android:shape=”rectangle”> <solid android:color=”#CABBBBBB”/> <corners android:radius=”2dp” /> </shape> </item> <item android:left=”0dp” android:right=”0dp” android:top=”0dp” android:bottom=”2dp”> <shape android:shape=”rectangle”> <solid android:color=”@android:color/white”/> <corners android:radius=”2dp” /> </shape> </item> </layer-list>

frequent issues arising in android view, Error parsing XML: unbound prefix

A couple of reasons that this can happen: 1) You see this error with an incorrect namespace, or a typo in the attribute. Like ‘xmlns’ is wrong, it should be xmlns:android 2) First node needs to contain: xmlns:android=”http://schemas.android.com/apk/res/android” 3) If you are integrating AdMob, check custom parameters like ads:adSize, you need xmlns:ads=”http://schemas.android.com/apk/lib/com.google.ads” 4) If you … Read more

Linear Layout and weight in Android

3 things to remember: set the android:layout_width of the children to “0dp” set the android:weightSum of the parent (edit: as Jason Moore noticed, this attribute is optional, because by default it is set to the children’s layout_weight sum) set the android:layout_weight of each child proportionally (e.g. weightSum=”5″, three children: layout_weight=”1″, layout_weight=”3″, layout_weight=”1″) Example: <LinearLayout android:layout_width=”fill_parent” … Read more