<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-9106967537835418775</id><updated>2026-09-19T04:33:22.065-07:00</updated><category term="android"/><category term="Liner Layout"/><category term="eclipse"/><category term="JNI"/><category term="Java"/><category term="base line"/><category term="custom view"/><category term="grid view"/><category term="Adaptor"/><category term="Cache"/><category term="ClipDrawable"/><category term="Connection Point"/><category term="DeleteLocalRe"/><category term="Eclipse Template"/><category term="Expand"/><category term="Grid"/><category term="If block"/><category term="Index"/><category term="Issue"/><category term="Java Reference"/><category term="Logging"/><category term="MP3"/><category term="PopLocalFrame"/><category term="PushLocalFrame"/><category term="Random"/><category term="Relative Layout"/><category term="Single line"/><category term="Thinking pattern"/><category term="UI Automator Viewer"/><category term="Unique"/><category term="Visio"/><category term="Weak Reference"/><category term="alignment"/><category term="ant"/><category term="bitmap"/><category term="both side clipped progress bar"/><category term="call back"/><category term="changing"/><category term="cvs"/><category term="immutable"/><category term="layout transition"/><category term="left to right"/><category term="looping"/><category term="looping count"/><category term="media scanner"/><category term="mutable"/><category term="no duplicate"/><category term="parentage size"/><category term="persist data"/><category term="process thinking pattern"/><category term="project preparation"/><category term="r theta"/><category term="reference table"/><category term="release resources"/><category term="setDataSource"/><category term="templates"/><category term="text drawing"/><category term="thread"/><category term="top to bottom"/><category term="uiautomatorviewer"/><category term="weighted size"/><category term="windows 7"/><title type='text'>Thoughts of &quot;Sudar Nimalan&quot;</title><subtitle type='html'>...for you to comment ...</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>43</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-8951736114622572274</id><published>2015-07-17T22:15:00.000-07:00</published><updated>2015-07-17T22:18:52.150-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DeleteLocalRe"/><category scheme="http://www.blogger.com/atom/ns#" term="JNI"/><category scheme="http://www.blogger.com/atom/ns#" term="PopLocalFrame"/><category scheme="http://www.blogger.com/atom/ns#" term="PushLocalFrame"/><category scheme="http://www.blogger.com/atom/ns#" term="reference table"/><title type='text'>JNI Error: Local reference table overflow</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
If you are working on JNI, you may have faced issue:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: purple;&quot;&gt;&quot;Local reference table overflow 512 entries&quot;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Say you have following code, you will immediately get this issue. &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;i&gt;void methodOne()&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;i&gt;{&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;for(int i = 0 ; i &amp;lt; &lt;b&gt;1000 &lt;/b&gt;; i++)&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;jobject localReferenceOne = ...;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;methodTwo(localReferenceOne);&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;i&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;i&gt;void methodTwo(jobject parameter)&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;i&gt;{&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;jobejct localReferenceTwo = ...;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;i&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
First You should delete all local reference once you are done with that.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;void methodOne()&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;{&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;for(int i = 0 ; i &amp;lt; 1000 ; i++)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;jobject localReferenceOne = ...;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;methodTwo(localReferenceOne);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;env-&amp;gt;DeleteLocalRef(localReferenceOne);&lt;/b&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;
&lt;i&gt;void methodTwo(jobject &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;parameter&lt;/span&gt;&lt;/b&gt;)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;{&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;jobejct localReferenceTwo = ...;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;...&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;env-&amp;gt;DeleteLocalRef(localReferenceOne);&lt;/b&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
But you will still faces the issue. This is because &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;parameter &lt;/span&gt;&lt;/b&gt;also local reference. You cannot delete the parameter using &lt;i&gt;&lt;b&gt;DeleteLocalRef&lt;/b&gt;&lt;/i&gt;. To delete parameter local reference you need to call &lt;i&gt;&lt;b&gt;PushLocalFrame &lt;/b&gt;&lt;/i&gt;and &lt;i&gt;&lt;b&gt;PopLocalFrame &lt;/b&gt;&lt;/i&gt;before and after method call.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;void methodOne()&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;{&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;for(int i = 0 ; i &amp;lt; 1000 ; i++)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;env-&amp;gt;PushLocalFrame(0);&lt;/b&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;jobject localReferenceOne = ...;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;methodTwo(localReferenceOne);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;env-&amp;gt;DeleteLocalRef(localReferenceOne);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;env-&amp;gt;PopLocalFrame(0);&lt;/b&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;
&lt;i&gt;void methodTwo(jobject &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;parameter&lt;/b&gt;&lt;/span&gt;)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;{&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;jobejct localReferenceTwo = ...;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;...&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;env-&amp;gt;DeleteLocalRef(localReferenceOne);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/8951736114622572274/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/8951736114622572274' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/8951736114622572274'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/8951736114622572274'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2015/07/jni-error-local-reference-table-overflow.html' title='JNI Error: Local reference table overflow'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-7498296471007717495</id><published>2014-04-15T01:00:00.000-07:00</published><updated>2014-04-15T01:00:59.594-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="call back"/><category scheme="http://www.blogger.com/atom/ns#" term="JNI"/><title type='text'>Android JNI Call back</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvLcgF0btT8OMqB9zx_6vOx8za0Sm87OBLYoPCJN_gwCL93SMGpAnQqJA4Xrc_-oy3J6rJrP9VOQe5YXsdC3ijju8Id0KIyAb1kgFNb24_f-1B6-LdcMTzAeYI1zVmv34wC-6oBi37quo/s1600/Android+JNI.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvLcgF0btT8OMqB9zx_6vOx8za0Sm87OBLYoPCJN_gwCL93SMGpAnQqJA4Xrc_-oy3J6rJrP9VOQe5YXsdC3ijju8Id0KIyAb1kgFNb24_f-1B6-LdcMTzAeYI1zVmv34wC-6oBi37quo/s1600/Android+JNI.jpg&quot; height=&quot;300&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
In the above images shows all possible scenarios of Android JNI calls and its call backs.&lt;br /&gt;
&lt;br /&gt;
Android UI mostly implemented in Java, then if needed there will be C++ implementation to&amp;nbsp;&amp;nbsp;perform low level operations. In this case JNI is used.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;1. Java to C++ calls :&lt;/b&gt;&lt;br /&gt;
First UI will need to make some call to C++, for example start engine etc.&lt;br /&gt;
&lt;br /&gt;
In Java:&lt;br /&gt;
1.1. Need to write a native method:&lt;br /&gt;
&lt;b&gt;package demo;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;class Service{&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;public static &lt;span style=&quot;color: red;&quot;&gt;native &lt;/span&gt;doSomething();&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;}&lt;/b&gt;&lt;br /&gt;
1.2. Call this method to invoke/access the low level.&lt;br /&gt;
&lt;b&gt;....&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;//Somewhere&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Service.doSomething();&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;....&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In C++:&lt;br /&gt;
1.2. Need to write the implementation for above native method:&lt;br /&gt;
&lt;b&gt;JNIEXPORT jint JNICALL Java_demo_Service_doSomeThing(JNIEnv * env, jobject ){&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;..............&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;..............&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;}&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2. C++ to Java Call&lt;/b&gt;&lt;br /&gt;
There may be some cases C++ Implementation may need to call back UI, for example inform the progress update.&lt;br /&gt;
This can happen from the same thread which the initial called made from Java or C++ may have created a new thread and may call from there.&lt;br /&gt;
&lt;br /&gt;
In Java: Write a Observer to receive those call backs.&lt;br /&gt;
&lt;b&gt;package demo;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;class Service{&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;public static&amp;nbsp;void onCallBack(){&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ............&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //add implementation to handle call back&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...............&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;}&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Any callback from C++ to Java need to be implemented using given JNI refection APIs.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;jclass jcls = env-&amp;gt;FindClass(&quot;dem/Service&quot;);&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;jmethodID mid = env-&amp;gt;GetStaticMethodID(jcls,&quot;onCallBack&quot;,&quot;....&quot;);&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;env-&amp;gt;CallStaticVoidMethod(jcls,mid);&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This will perform what we want, but we will need some more extra implementation to make it work in caseof concurrent access from c++.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2.1 Calling from same thread.&lt;/b&gt;&lt;br /&gt;
In this case, the above listing will work without any issue. We can use the same &lt;b&gt;JNIEnv &lt;/b&gt;which passed in&amp;nbsp;&lt;b&gt;Java_demo_Service_doSomeThing &lt;/b&gt;call above 1.2&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2.2 Calling from other thread&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
In this case we cannot use the above env passed with&amp;nbsp;&lt;b&gt;Java_demo_Service_doSomeThing &amp;nbsp;&lt;/b&gt;&amp;nbsp;as it is invalid in other threads.&lt;br /&gt;
So We have to create a new &lt;b&gt;JNIEnv &lt;/b&gt;using &lt;b&gt;JavaVM, &lt;/b&gt;which is passed in&amp;nbsp;&lt;b&gt;JNI_OnLoad.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;So,&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;2.2.1 Write a&amp;nbsp;JNI_OnLoad in your native c++ code:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;static JavaVM * s_Jvm;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;{&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s_Jvm = vm;//Keep for future use.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return JNI_VERSION_1_6;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;}&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2.2.2 Attach Current Thread to create JNIEnv:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;JNIEnv * env;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;s_Jvm-&amp;gt;&lt;/b&gt;AttachCurrentThread(&amp;amp;env,NULL);&lt;br /&gt;
&lt;br /&gt;
2.2.3 If you try FindClass with this JNIEnv it will return NULL in Android since uses special Class Loader in Java and in New thread which created in C++ will use the&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;jclass jcls = env-&amp;gt;FindClass(&quot;dem/Service&quot;);&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
2.2.4 So this should be done inside OnLoad method : &lt;b&gt;(code are in bold) &lt;/b&gt;and assign to global reference to use in future.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;jclass s_jcls;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s_Jvm = vm;//Keep for future use.&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s_jcls = &amp;nbsp;env-&amp;gt;NewGlobalRef(env-&amp;gt;FindClass(&quot;dem/Service&quot;));&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;return JNI_VERSION_1_6;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;2.2.5 Now you can use this s_jcls to make any call backs&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;GetStaticMethodID&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;pPreformatted&quot; style=&quot;background-color: white;&quot;&gt;CallStaticObjectMethod&lt;/pre&gt;
&lt;pre class=&quot;pPreformatted&quot; style=&quot;background-color: white;&quot;&gt;&lt;/pre&gt;
&lt;pre class=&quot;pPreformatted&quot; style=&quot;background-color: white;&quot;&gt;etc...&lt;/pre&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/7498296471007717495/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/7498296471007717495' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/7498296471007717495'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/7498296471007717495'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2014/04/android-jni-call-back.html' title='Android JNI Call back'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvLcgF0btT8OMqB9zx_6vOx8za0Sm87OBLYoPCJN_gwCL93SMGpAnQqJA4Xrc_-oy3J6rJrP9VOQe5YXsdC3ijju8Id0KIyAb1kgFNb24_f-1B6-LdcMTzAeYI1zVmv34wC-6oBi37quo/s72-c/Android+JNI.jpg" height="72" width="72"/><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-4326238485290401455</id><published>2014-01-25T07:31:00.001-08:00</published><updated>2014-01-25T07:31:58.424-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Connection Point"/><category scheme="http://www.blogger.com/atom/ns#" term="Visio"/><title type='text'>Visio: Adding New Connection Points to Shape</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Step 1: Click on the X icon next to connection icon&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjg6C0a9q21SsK8POnVJsN_lTgjXh7Ort_uaPbWcE0u1_NBW5vq6NOWDBXnMMv0O7EK67H9ImALNYzSOF9qp3-A4uUnTXsa0A_uVr6KAESxl-apdLOCuPFlryK-Kbu6kjntItgTW8fhEU/s1600/visio_01.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjg6C0a9q21SsK8POnVJsN_lTgjXh7Ort_uaPbWcE0u1_NBW5vq6NOWDBXnMMv0O7EK67H9ImALNYzSOF9qp3-A4uUnTXsa0A_uVr6KAESxl-apdLOCuPFlryK-Kbu6kjntItgTW8fhEU/s1600/visio_01.jpg&quot; height=&quot;222&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzitBKcyoXZqj7zct77aMrnSN-IZFSgY0LRFsCI886pWqQuZMUYJrg6Vg34p-x42PwqB-6D4uflEqeBo_qnC30m0oxrl03gtmQrSuykyEpCfuZVIkurdtEmAi0MLfsmiMkPAWZsGa8LLc/s1600/visio_01_01.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzitBKcyoXZqj7zct77aMrnSN-IZFSgY0LRFsCI886pWqQuZMUYJrg6Vg34p-x42PwqB-6D4uflEqeBo_qnC30m0oxrl03gtmQrSuykyEpCfuZVIkurdtEmAi0MLfsmiMkPAWZsGa8LLc/s1600/visio_01_01.jpg&quot; height=&quot;214&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;Step 2: Press Ctrl and click on the Shape where you want the new connection point.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjeH9PAalS9vtrlpbP5TdYSidkdczmm9zvu6QbuWpjnJ-RBe_KmPyAGtlWS_k6Usu6Aq3CkEID-xM4iOZjdu0AR-viB6x6N2rAUlMcdgdHJldrFMzoGQpAzoOmJg_OkALtv0poogSYXik/s1600/visio_02.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjeH9PAalS9vtrlpbP5TdYSidkdczmm9zvu6QbuWpjnJ-RBe_KmPyAGtlWS_k6Usu6Aq3CkEID-xM4iOZjdu0AR-viB6x6N2rAUlMcdgdHJldrFMzoGQpAzoOmJg_OkALtv0poogSYXik/s1600/visio_02.png&quot; height=&quot;222&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz7yXH2XwhzlEiPuQn7xhVB82u77lphIGXD-8Q11bpaSwuxLkAtcRyLFWpiP5dDHiJk08ClVjc0tO0K-fILufQYL1URSfQ6dbkPqb0yL-YFbeNStALYcvH-T1YCgfyziGXMA7dxwT-P4c/s1600/visio_02_02.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz7yXH2XwhzlEiPuQn7xhVB82u77lphIGXD-8Q11bpaSwuxLkAtcRyLFWpiP5dDHiJk08ClVjc0tO0K-fILufQYL1URSfQ6dbkPqb0yL-YFbeNStALYcvH-T1YCgfyziGXMA7dxwT-P4c/s1600/visio_02_02.png&quot; height=&quot;240&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/4326238485290401455/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/4326238485290401455' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/4326238485290401455'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/4326238485290401455'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2014/01/visio-adding-new-connection-points-to.html' title='Visio: Adding New Connection Points to Shape'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjg6C0a9q21SsK8POnVJsN_lTgjXh7Ort_uaPbWcE0u1_NBW5vq6NOWDBXnMMv0O7EK67H9ImALNYzSOF9qp3-A4uUnTXsa0A_uVr6KAESxl-apdLOCuPFlryK-Kbu6kjntItgTW8fhEU/s72-c/visio_01.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-3445413239159227130</id><published>2013-10-08T00:55:00.001-07:00</published><updated>2014-06-30T23:54:06.601-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ant"/><category scheme="http://www.blogger.com/atom/ns#" term="cvs"/><category scheme="http://www.blogger.com/atom/ns#" term="eclipse"/><category scheme="http://www.blogger.com/atom/ns#" term="windows 7"/><title type='text'>Eclipse, Ant, CVS with Windows 7 </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I got a new machine with Windows 7, and started to setup my build environment.&lt;br /&gt;
&lt;br /&gt;
We have an ant script to update from CVS and tag and etc...&lt;br /&gt;
&lt;br /&gt;
Simply adding following ant task I could do this.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;lt;target name=&quot;cvs_update&quot;&amp;gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&amp;lt;cvs command=&quot;update -dP&quot;&amp;gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&amp;lt;/cvs&amp;gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;lt;/target&amp;gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;lt;target name=&quot;cvs_tag&quot;&amp;gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&amp;lt;cvs command=&quot;tag ABC_${build_time}&quot;&amp;gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&amp;lt;/cvs&amp;gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;lt;/target&amp;gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
But, we should install WinCVS/CVSNT to run this &lt;cvs&gt; task.&lt;/cvs&gt;&lt;br /&gt;
&lt;br /&gt;
In Windows 7 I got a first issue, ant couldn&#39;t find the cvs.exe even if the cvs.exe in PATH variable. And if you check the in command prompt by type cvs it will run. But in Eclipse when you run above ant task it will keep saying application cvs not found.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;[cvs] Caught exception: Cannot run program &quot;cvs&quot;: CreateProcess error=2, The system cannot find the file specified&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Only solution I found is:&lt;br /&gt;
uninstall and install CVSNT into a folder, which name doesn&#39;t have any spaces (Example Program_Files_(x86))&lt;br /&gt;
&lt;br /&gt;
The 2nd I faced in login&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&amp;nbsp;[cvs] cvs update: Empty password used - try &#39;cvs login&#39; with a real password [cvs]&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;
The only solution I found is:&lt;br /&gt;
Run CVSNT Password Agent.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/3445413239159227130/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/3445413239159227130' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/3445413239159227130'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/3445413239159227130'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2013/10/eclipse-ant-cvs-with-windows-7.html' title='Eclipse, Ant, CVS with Windows 7 '/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-4750131341496349583</id><published>2013-05-18T04:41:00.001-07:00</published><updated>2013-05-18T04:41:25.250-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="eclipse"/><category scheme="http://www.blogger.com/atom/ns#" term="If block"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Single line"/><title type='text'>Eclipse, Java : Inserting Single line &quot;if block&quot;</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
If we run our program after completing coding, those will not as excepted mostly, or at-least in testing we will find places where we have missed some null check or etc. So we may have to add a if condition to check and to avoid those&amp;nbsp;Exceptions. Mostly those will be a single line &quot;if blocks&quot;.&lt;br /&gt;
&lt;br /&gt;
I am talking about cases like below. Say you have following line:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;myObject.myMethod();&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Here we got a NullPointerException because myObject is null, I wanted added a null check before this:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if(myObject!=null)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;myObject.myMethod();&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This is correct, but I mostly don&#39;t like this, for future coding and&amp;nbsp;because&amp;nbsp;of the&amp;nbsp;readability, I&amp;nbsp;prefer to add a block as follows. Sometime reader will think that, all the statements which following the above statement also inside the if condition.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if(myObject!=null){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;myObject.myMethod();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
It was hard for me always,&amp;nbsp;because&amp;nbsp;I had to write if block and copy paste the&amp;nbsp;statement inside. But i found a method to do in Eclipse without &amp;nbsp;doing &amp;nbsp;copy paste.&lt;br /&gt;
&lt;br /&gt;
Just go infront of the statement and start typing your if condition and write up to { and press enter key, then you will get what you want.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if(myObject!=null){&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;|&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: blue;&quot;&gt;myObject.myMethod(); &lt;-- font=&quot;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Keep the curser at the | position and press enter.&lt;/b&gt;&lt;/span&gt;&lt;/--&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
Okey now you try and let me know your comments.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/4750131341496349583/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/4750131341496349583' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/4750131341496349583'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/4750131341496349583'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2013/05/eclipse-java-inserting-single-line-if.html' title='Eclipse, Java : Inserting Single line &quot;if block&quot;'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-4915511587490916056</id><published>2013-01-30T01:22:00.000-08:00</published><updated>2014-04-16T18:58:37.442-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="Eclipse Template"/><category scheme="http://www.blogger.com/atom/ns#" term="Weak Reference"/><title type='text'>Part 2:Useful Eclipse Templates for Android Development</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;a href=&quot;http://sudarnimalan.blogspot.sg/2012/06/useful-eclipse-templates-for-android.html&quot;&gt;Part 1:Useful Eclipse Templates for Android Development&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/b&gt;
&lt;b&gt;&lt;u&gt;Weak Reference for Views in&amp;nbsp;Activity.&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Inside&amp;nbsp;&lt;b&gt;&lt;i&gt;onCreate &lt;/i&gt;&lt;/b&gt;of each Android&amp;nbsp;Activity we used to&amp;nbsp;&lt;b&gt;&lt;i&gt;setContentView &lt;/i&gt;&lt;/b&gt;with layout xml. Then to access each view from the activity we use:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;View view = findViewById(R.id..........);&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
to&amp;nbsp;avoid calling &amp;nbsp;&lt;b&gt;&lt;i&gt;findViewById&amp;nbsp;&lt;/i&gt;&lt;/b&gt;multiple&amp;nbsp;time, &amp;nbsp;call this only in &lt;b&gt;&lt;i&gt;onCreate &lt;/i&gt;&lt;/b&gt;and keep this view as member variable inside&amp;nbsp;activity.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;View mView&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;
&lt;b&gt;&lt;i&gt;.....&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;mView = findViewById(R.id..........);&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;
Then, question is why we need to overload the onCreate method, we call&amp;nbsp;&lt;b style=&quot;font-style: italic;&quot;&gt;findViewById &lt;/b&gt;only when needed and keep as member variable. So introduce following get method.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;View getView(){&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if(mView==null){&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mView = findViewById(R.id..........);&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;return mView;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;}&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;
But in some cases, to avoid memory leakage issues, we need to remove all view from content view and need to &lt;b&gt;&lt;i&gt;null &lt;/i&gt;&lt;/b&gt;all these references in&amp;nbsp;activity. But rather find each reference and assign to null, if we make a weak&amp;nbsp;reference then it should all clear as we remove view from activity. For Example:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;private WeakReference&lt;view&gt; mView;&lt;/view&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;public View getView() {&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(!(mView!=null &amp;amp;&amp;amp; mView.get()!=null)){&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;mView = new WeakReference&lt;view&gt;((View) findViewById(R.id.....));&lt;/view&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return mFrameAddStyleView.get();&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;}&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Now, Let see how to write a Eclipse template to auto generate this:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Eclipse - &amp;gt; Windows -&amp;gt; Preferences -&amp;gt; Java -&amp;gt; Editor -&amp;gt; Templates -&amp;gt; New ...&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Name:-&amp;nbsp;&lt;span id=&quot;internal-source-marker_0.5145275429822505&quot;&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;wfind&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt;Pattern:- &lt;/i&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b id=&quot;internal-source-marker_0.5145275429822505&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;private WeakReference&amp;lt;${type}&amp;gt; m${new_name};&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;public ${type} get${new_name}() {&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(!(m${new_name}!=null &amp;amp;&amp;amp; m${new_name}.get()!=null)){&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;m${new_name} = new WeakReference&amp;lt;${type}&amp;gt;((${type}) findViewById(R.id.${cursor}));&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return m${new_name}.get();&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;i&gt;}&lt;/i&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br class=&quot;kix-line-break&quot; /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;b style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;Now go to your activity class and type wfind and press Ctrl+Space you will get what you want.&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/4915511587490916056/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/4915511587490916056' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/4915511587490916056'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/4915511587490916056'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2013/01/part-2useful-eclipse-templates-for.html' title='Part 2:Useful Eclipse Templates for Android Development'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-5761554575393174771</id><published>2012-11-15T21:20:00.002-08:00</published><updated>2012-11-15T21:20:49.011-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="UI Automator Viewer"/><category scheme="http://www.blogger.com/atom/ns#" term="uiautomatorviewer"/><title type='text'>Android: UI Automator Viewer (uiautomatorviewer) - issue in landscape screen </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
If you are ttrying to use&amp;nbsp;&lt;a href=&quot;http://developer.android.com/tools/testing/testing_ui.html&quot;&gt;UI Testing&lt;/a&gt; tools introduced in&amp;nbsp;&lt;a href=&quot;http://android-developers.blogspot.sg/2012/11/android-sdk-tools-revision-21.html&quot;&gt;Android SDK Tools, Revision 21&amp;nbsp;&lt;/a&gt;&amp;nbsp;you will see a&amp;nbsp;port-tailed image in uiautomatorviewer&amp;nbsp;capture&amp;nbsp;for landscape activities.&lt;br /&gt;
Hover over selection and uix file will perform properly, but only issue will be the image will not be&amp;nbsp;aligned&amp;nbsp;properly.&lt;br /&gt;
I found a possible workaround, just close the file (note down the location) and got the folder, you will see a image, please rotate accordingly.&lt;br /&gt;
Then come back and reopen the uix, it will ask for the screen slot, just show the&amp;nbsp;rotated screen.&amp;nbsp;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/5761554575393174771/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/5761554575393174771' title='17 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/5761554575393174771'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/5761554575393174771'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2012/11/android-ui-automator-viewer.html' title='Android: UI Automator Viewer (uiautomatorviewer) - issue in landscape screen '/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>17</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-4471208444274715372</id><published>2012-10-02T18:18:00.000-07:00</published><updated>2012-11-03T07:38:27.455-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Index"/><category scheme="http://www.blogger.com/atom/ns#" term="no duplicate"/><category scheme="http://www.blogger.com/atom/ns#" term="Random"/><category scheme="http://www.blogger.com/atom/ns#" term="Unique"/><title type='text'>Java: Random Unique Indexes</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Say you have a list of items, you want to pick item from the list in random order, but need to avoid&amp;nbsp;duplicate items until you get all items from the list.&lt;br /&gt;
assume below list of colors&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;0. Red&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;1. Blue&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;2. Yellow&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;3. Green&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
You may have to display as Blue, Red, Yellow and Green, here you see we have random items but not duplicated.&lt;br /&gt;
&lt;br /&gt;
Here I write a Java Utilities for that purpose. Here we have to generate random numbers with in the limit but we have to ignore already generated values when try next time.&lt;br /&gt;
&lt;br /&gt;
So,&amp;nbsp;First create a list of indexes.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;[0]-&amp;gt;0&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;[1]-&amp;gt;1&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;[2]-&amp;gt;2&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;[3]-&amp;gt;3&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;mIndexes = new int[size];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;for(int i = 0 ; i &amp;lt; mIndexes.length;i++){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;mIndexes[i] = i;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
First you have to create a random number within the size so,&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;mNextMaxIndex = size;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Let see how to generate random index with no duplicate.&lt;br /&gt;
Generate a random index with the size limit.&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;int index = mRandom.nextInt(mNextMaxIndex);&lt;/span&gt;&lt;br /&gt;
Value from the index will be the result.&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;int result = mIndexes[index];&lt;/span&gt;&lt;br /&gt;
now swap this value to end of the effect list and reduce the limit by one.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;mNextMaxIndex--;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;mIndexes[index] = mIndexes[mNextMaxIndex];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;mIndexes[mNextMaxIndex] = result;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Say you got 2 then result will be 2 and our new list will be&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;[0]-&amp;gt;0&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;[1]-&amp;gt;1&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;[2]-&amp;gt;3&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;[3]-&amp;gt;2&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
and&amp;nbsp;mNextMaxIndex will be 3.&lt;br /&gt;
Now for the next index, generate a random number within 3 and do the same steps again.&lt;br /&gt;
But&amp;nbsp;finally if we reach the start we have to reset back start from the end.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;if(mNextMaxIndex&lt;1 font=&quot;font&quot;&gt;&lt;!--1--&gt;&lt;!--1--&gt;&lt;/1&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;mNextMaxIndex = mIndexes.length;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I have the&lt;a href=&quot;http://dl.dropbox.com/u/7717254/RandomUniqueIndexGenerator.java&quot;&gt; source code&lt;/a&gt; here, it have a main method to test his also i see a&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/4471208444274715372/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/4471208444274715372' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/4471208444274715372'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/4471208444274715372'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2012/10/java-random-unique-indexex.html' title='Java: Random Unique Indexes'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-8040195976439740602</id><published>2012-09-20T19:30:00.000-07:00</published><updated>2012-09-20T19:30:12.421-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="Issue"/><category scheme="http://www.blogger.com/atom/ns#" term="MP3"/><category scheme="http://www.blogger.com/atom/ns#" term="setDataSource"/><title type='text'>Android: Issue In loading MP3 files, which Saved by Same Application</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
We had to list down and play some bundled MP3 files from our android application. We added a zip file with proper folder&amp;nbsp;structure inside assert. Application will extract that into /data/data/{package name}/files/ &amp;nbsp;folder on loading and make use of this.&lt;br /&gt;
In this both Media Metadata&amp;nbsp;Retriever or Media Player&amp;nbsp;&amp;nbsp;API didn&#39;t work if we use&amp;nbsp;direct&amp;nbsp;file-name&amp;nbsp;or URI.&lt;br /&gt;
First I was&amp;nbsp;thinking the issue in permission of the written file, I manage to write files with the permission -rw-rw-rw but that was not enough. Issue was with owner. Those written files owner and group as same as the&amp;nbsp;application&amp;nbsp;not root or etc.&lt;br /&gt;
I couldn&#39;t find a API to change the owner of a file.But lucky, Media Metadata Retriever and Media Player API could accept File Descriptor, So We had to use FileInputStream to get The File Descriptor and pass it to tose APIs.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/8040195976439740602/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/8040195976439740602' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/8040195976439740602'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/8040195976439740602'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2012/09/android-issue-in-loading-mp3-files.html' title='Android: Issue In loading MP3 files, which Saved by Same Application'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-3780085073664730337</id><published>2012-08-22T08:50:00.000-07:00</published><updated>2012-08-22T08:56:05.427-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="changing"/><category scheme="http://www.blogger.com/atom/ns#" term="layout transition"/><title type='text'>Android: Layout Transition CHANGING animation for API level 11-15</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In android, &lt;a href=&quot;http://developer.android.com/reference/android/animation/LayoutTransition.html&quot;&gt;Layout Transition&lt;/a&gt; is introduced from API level 11. By enabling layout transition application can get predefine platform animations for following  changes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. APPEARING - animation that runs on those items that are appearing in the container.&lt;br /&gt;
2. CHANGE_APPEARING - animation that runs on those items that are changing due to a new item appearing in the container.&lt;br /&gt;
3. CHANGE_DISAPPEARING - animation that runs on those items that are changing due to an item disappearing from the container.&lt;br /&gt;
4. DISAPPEARING - animation that runs on those items that are disappearing from the container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These are fast, tested, easy to incorporate with our applications.&lt;br /&gt;
&lt;br /&gt;
CHANGING animation was not added to API at that time, but it has been added now in API level 16.&lt;br /&gt;
&lt;br /&gt;
CHANGING - animation that runs on those items that are changing due to a layout change not caused by items being added to or removed from the container.&lt;br /&gt;
&lt;br /&gt;
So incase if we want to support devices in API level 11, it is good to have some work around, and it should be able to get platform animation in other decides more than API level 16.&lt;br /&gt;
&lt;br /&gt;
I am trying to make a utility for this to simply incorporate this and here I have two options.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;1. Simple One time registration/setup, but this will not support scroll changes or any other property changes. only support left, top, right and bottom.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
First we register on layout change listener for both layout and its children. So as soon as there is a layout change in these views the callback will be called.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;private static void setupChangeAnimationOneTime(final View view) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;final View.OnLayoutChangeListener onLayoutChangeListener = new View.OnLayoutChangeListener() {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;@Override&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;public void onLayoutChange(View v, int left, int top, int right,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;...&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;};&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;view.addOnLayoutChangeListener(onLayoutChangeListener);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here, create a object animator, with old and new values.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;PropertyValuesHolder pvhLeft = PropertyValuesHolder.ofInt(&quot;left&quot;, oldLeft, left);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;PropertyValuesHolder pvhTop = PropertyValuesHolder.ofInt(&quot;top&quot;, oldTop, top);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;PropertyValuesHolder pvhRight = PropertyValuesHolder.ofInt(&quot;right&quot;, oldRight, right);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;PropertyValuesHolder pvhBottom = PropertyValuesHolder.ofInt(&quot;bottom&quot;, oldBottom, bottom);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;ObjectAnimator changeAnimator = ObjectAnimator.ofPropertyValuesHolder((Object)view,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pvhLeft, pvhTop, pvhRight, pvhBottom);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;changeAnimator.setDuration(600);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start the animator.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;changeAnimator.start();&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
In this option, we don&#39;t know other property of the view. so we cannot animate them.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;2. Advanced approach, setup in each layout changes, for this the root layout needed to be a custom layout, where the onlayout method should be overridden or need to find a proper action where the layout change is&amp;nbsp;happened&amp;nbsp;(example onClick etc).&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First create an animator with properties you wanted animate. Use null for target object and some arbitrary values, which will be changed in setup.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;public static ObjectAnimator getDefaultChangeAnimator(){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(sDefaultChangeAnimator==null){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PropertyValuesHolder pvhLeft = PropertyValuesHolder.ofInt(&quot;left&quot;, 0, 1);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PropertyValuesHolder pvhTop = PropertyValuesHolder.ofInt(&quot;top&quot;, 0, 1);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PropertyValuesHolder pvhRight = PropertyValuesHolder.ofInt(&quot;right&quot;, 0, 1);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PropertyValuesHolder pvhBottom = PropertyValuesHolder.ofInt(&quot;bottom&quot;, 0, 1);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PropertyValuesHolder pvhScrollX = PropertyValuesHolder.ofInt(&quot;scrollX&quot;, 0, 1);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PropertyValuesHolder pvhScrollY = PropertyValuesHolder.ofInt(&quot;scrollY&quot;, 0, 1);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sDefaultChangeAnimator = ObjectAnimator.ofPropertyValuesHolder((Object)null,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pvhLeft, pvhTop, pvhRight, pvhBottom, pvhScrollX, pvhScrollY);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sDefaultChangeAnimator.setDuration(600);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return sDefaultChangeAnimator;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the animator has to be setup just before the layout change of the layout and it&#39;s children. First start state will be setup and&amp;nbsp;layout change listener wil be&amp;nbsp;registered.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;private static void setupChangeAnimation(final View view) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;…&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;changeAnimator.setTarget(view);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;…&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;changeAnimator.setupStartValues();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;final View.OnLayoutChangeListener onLayoutChangeListener = new View.OnLayoutChangeListener() {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;@Override&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;public void onLayoutChange(View v, int left, int top, int right,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;changeAnimator.setupEndValues();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;changeAnimator.start();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;…&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;};&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;changeAnimator.addListener(animatorListener);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;view.addOnLayoutChangeListener(onLayoutChangeListener);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
after layout change, inside the on layout change callback the end state of the animator will be setup and start&amp;nbsp;immediately.&lt;br /&gt;
&lt;br /&gt;
Here &amp;nbsp;we need to make sure&amp;nbsp;setupChangeAnimation called just before the layout change. For this we have two possible place,&lt;br /&gt;
1. inside the onlayout call of animation enabled layout.&lt;br /&gt;
2. posible action code that make layout&amp;nbsp;changes. (example onClick())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;public class DemoLinearLayout extends LinearLayout {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;protected void onLayout(boolean changed, int l, int t, int r, int b) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;LayoutTransitionUtil.checkAndSetupChangeAnimationForAllChild(this);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;super.onLayout(changed, l, t, r, b);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;@Override&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;public void onClick(View view) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;LayoutTransitionUtil.setupChangeAnimation((ViewGroup)findViewById(R.id.frm_linear_04));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here I am uploading the &lt;a href=&quot;http://dl.dropbox.com/u/7717254/DemoLayoutTransition.zip&quot;&gt;sample source code&lt;/a&gt; for reference.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/3780085073664730337/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/3780085073664730337' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/3780085073664730337'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/3780085073664730337'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2012/08/android-layout-transition-changing.html' title='Android: Layout Transition CHANGING animation for API level 11-15'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-1487231275640914882</id><published>2012-08-16T00:39:00.001-07:00</published><updated>2012-08-16T00:39:59.302-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="Liner Layout"/><category scheme="http://www.blogger.com/atom/ns#" term="parentage size"/><category scheme="http://www.blogger.com/atom/ns#" term="Relative Layout"/><category scheme="http://www.blogger.com/atom/ns#" term="weighted size"/><title type='text'>Android: Relative Layout with weighted size</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Android applications should support&amp;nbsp;multiple&amp;nbsp;screens, So absolute values cannot be used in layouts. Mostly Relative Layout or Liner Layout is used in UI&amp;nbsp;arrangements, In Relative&amp;nbsp;Layout, views can be&amp;nbsp;arranged&amp;nbsp;relatively. for example one button can be arranged &amp;nbsp;below&amp;nbsp;&amp;nbsp;to another etc. But, only in Liner Layout, views&#39; size can be specified with weight. i.e width of a view can be 70% of it parent&amp;nbsp;width&amp;nbsp;etc. This feature is very useful in&amp;nbsp;supporting&amp;nbsp;multiple&amp;nbsp;screens. Since it applies weight in vertically or horizontally at a time normally Liner Layout need to be nested. This may reduce the performance.&lt;br /&gt;
&lt;br /&gt;
So, It is better&amp;nbsp;introducing&amp;nbsp;weight&amp;nbsp;attributes for Relative Layout and will improve application&amp;nbsp;performance. If this can be done in Android API level it is easy since&amp;nbsp;already an&amp;nbsp;implementation&amp;nbsp;is there for Relative Layout. I see this is an enhancement for Relative Layout and no need to introduce another Layout, otherwise same code will be&amp;nbsp;duplicated.&lt;br /&gt;
&lt;br /&gt;
Lets&#39; try this with an example, Say If you want to create a layout as below:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimCxPxvdPHv4cw35X-RfuPfYQXUSccc1X6_gZ3gC5OTugfz-zVKPOXVNdh93QTJNZ2k4SoeBleSTE_INjNq-RywDGkFipnLYLhyphenhyphenbUPhL-B9DkTXVq2BBwok349XSY3IQzO-m_OeMhI10Y/s1600/Untitled+drawing+(1).jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;169&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimCxPxvdPHv4cw35X-RfuPfYQXUSccc1X6_gZ3gC5OTugfz-zVKPOXVNdh93QTJNZ2k4SoeBleSTE_INjNq-RywDGkFipnLYLhyphenhyphenbUPhL-B9DkTXVq2BBwok349XSY3IQzO-m_OeMhI10Y/s320/Untitled+drawing+(1).jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
The expectation is as below: setting layout_width=0dip and introducing layout_width_weight and set required value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;br /&gt;
&amp;lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; android:layout_width=&quot;match_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; android:layout_height=&quot;match_parent&quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;Button&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/button01&quot;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;0dip&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;android:layout_width_weight=&quot;0.2500&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;0dip&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;android:layout_height_weight=&quot;0.1666&quot;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:text=&quot;Button01&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;Button&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/button02&quot;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;0dip&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;android:layout_width_weight=&quot;0.2500&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;0dip&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;android:layout_height_weight=&quot;0.1666&quot;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_below=&quot;@+id/button01&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:text=&quot;Button02&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;Button&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/button03&quot;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;0dip&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;android:layout_width_weight=&quot;0.2500&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;0dip&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;android:layout_height_weight=&quot;0.1666&quot;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_below=&quot;@+id/button02&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:text=&quot;Button03&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;Button&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/button04&quot;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;0dip&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;android:layout_width_weight=&quot;0.5000&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;0dip&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;android:layout_height_weight=&quot;0.5000&quot;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_centerInParent=&quot;true&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:text=&quot;Button04&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;Button&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/button05&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;fill_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_alignParentRight=&quot;true&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_below=&quot;@id/button04&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:text=&quot;Button05&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/RelativeLayout&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I checked for&amp;nbsp;necessary changes in&amp;nbsp;Relative&amp;nbsp;Layout source code and found that,&lt;br /&gt;
&lt;br /&gt;
1. Both fields for holding weight values need to be added in RelativeLayout.LayoutParams class and loading this values into it.&lt;br /&gt;
2. new Parameter need &amp;nbsp;to be added to&amp;nbsp;RelativeLayout.getChildMeasureSpec method inorder to pass the value from&amp;nbsp;RelativeLayout.measureChild and&amp;nbsp;RelativeLayout.measureChildHorizontal methods.&lt;br /&gt;
3. Add extra condition if child size equals to zero then make use of the weight value inside&amp;nbsp;RelativeLayout.getChildMeasureSpec to calculate the size.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;private int getChildMeasureSpec(..., float weight){&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;...&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;&amp;nbsp;if (childSize == 0) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;childSpecMode = MeasureSpec.EXACTLY;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;childSpecSize = (int)(mySize*weight);&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;}else if(chileSize&amp;gt;0){&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;....&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;...&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
But before going for a Android API level change, It is better to try out. It is&amp;nbsp;impossible since it a private method, it cannot be&amp;nbsp;overridden.&lt;br /&gt;
&lt;br /&gt;
But this methods are called only in onMeasure, So I created a new layout by extending Relative Layout and copy source from Android API for those 4&amp;nbsp;methods(onMeasure,&amp;nbsp;measureChild,&amp;nbsp;measureChildHorizontal&amp;nbsp;and&amp;nbsp;getChildMeasureSpec), and since these methods use some private/hide methods/field from RelativeLayout and other Android API, I used Java Reflection to access them.&lt;br /&gt;
&lt;br /&gt;
Now, Since weight&amp;nbsp;attributes also not added into API using&amp;nbsp;&amp;nbsp;those in XML also impossible. But&amp;nbsp;lucky I found that negative values also can be set to layout_width and layout_height and only -1,-2 has used. So I try to use the negative values to&amp;nbsp;indicate those weight values and modify the condition in&amp;nbsp;getChildMeasureSpec&amp;nbsp;according&amp;nbsp;to that.&lt;br /&gt;
&lt;br /&gt;
I found more that, if we set negative px value then childSize will be one less than the value set in XML. Since childSize is integer number and get more&amp;nbsp;precision I go for 10,000&amp;nbsp;scaled weighted values.&lt;br /&gt;
&lt;br /&gt;
So the layout xml will be like this.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;br /&gt;
&amp;lt;demo.widget.WeightedSizeRelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; android:layout_width=&quot;match_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; android:layout_height=&quot;match_parent&quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;Button&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/button01&quot;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;-2501px&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;-1667px&quot;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:text=&quot;Button01&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;Button&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/button02&quot;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;-2501px&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;-1667px&quot;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_below=&quot;@+id/button01&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:text=&quot;Button02&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;Button&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/button03&quot;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;-2501px&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;-1667px&quot;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_below=&quot;@+id/button02&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:text=&quot;Button03&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;Button&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/button04&quot;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;-5001px&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;-5001px&quot;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_centerInParent=&quot;true&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:text=&quot;Button04&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;Button&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/button05&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;fill_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_alignParentRight=&quot;true&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_below=&quot;@id/button04&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:text=&quot;Button05&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/demo.widget.WeightedSizeRelativeLayout&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and the necessary changes for&amp;nbsp;getChildMeasureSpec method is this:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;private int getChildMeasureSpec(...){&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;........&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; if (childSize &amp;lt; -2 ) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Child wanted an exact size. Give as much as possible&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; childSpecMode = MeasureSpec.EXACTLY;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; childSpecSize = (int) (mySize*(-1.0f*childSize/10000));&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; }else if (childSize &amp;gt;= 0) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;.........&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I have uploaded both Java and demo xml &lt;a href=&quot;http://dl.dropbox.com/u/7717254/WeightedSizeRelativeLayout.zip&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Let test this and hope necessary&amp;nbsp;implementation for adding&amp;nbsp;weight attribute into Relative Layout&amp;nbsp;Parameter&amp;nbsp;will be added.&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/1487231275640914882/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/1487231275640914882' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/1487231275640914882'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/1487231275640914882'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2012/08/android-relative-layout-with-weighted.html' title='Android: Relative Layout with weighted size'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimCxPxvdPHv4cw35X-RfuPfYQXUSccc1X6_gZ3gC5OTugfz-zVKPOXVNdh93QTJNZ2k4SoeBleSTE_INjNq-RywDGkFipnLYLhyphenhyphenbUPhL-B9DkTXVq2BBwok349XSY3IQzO-m_OeMhI10Y/s72-c/Untitled+drawing+(1).jpg" height="72" width="72"/><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-3401820951862553201</id><published>2012-07-22T03:54:00.001-07:00</published><updated>2012-07-22T05:33:39.658-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="both side clipped progress bar"/><category scheme="http://www.blogger.com/atom/ns#" term="ClipDrawable"/><title type='text'>Android: Drawing both side clipped  Progress Bar</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
In most of the android application we can see some kind of progress bar with rounded corners as show below. Mostly in media players this used to indicate the curent duration and/or percentage of buffed content etc. These a mostly one side clipped. Let check how we can draw a both side clipped progress bar.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7awXl-1-3EvSBVvfPw2B5uWpo1N3Dvflw3f-siKwMO02CWEnDoPsns9Waez-45xKLs_DK2adc2axUvVTxL9v3uBglfA_xyXo4hCFMN9mZxdk6zWteXf8b7qlX3nSjVt_3YP-OQ_1dHLE/s1600/image&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;165&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7awXl-1-3EvSBVvfPw2B5uWpo1N3Dvflw3f-siKwMO02CWEnDoPsns9Waez-45xKLs_DK2adc2axUvVTxL9v3uBglfA_xyXo4hCFMN9mZxdk6zWteXf8b7qlX3nSjVt_3YP-OQ_1dHLE/s400/image&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Android API provide a build in progress bar, application developer can make use of this in their development. For that they manly use &lt;a href=&quot;http://developer.android.com/reference/android/graphics/drawable/ClipDrawable.html&quot;&gt;ClipDrawable&lt;/a&gt;. In android, In case of these kind of&amp;nbsp;stretchable&amp;nbsp;background we can use nine-patch drawable those will be stretched in runtime and reduce both memory usage of application.&lt;br /&gt;
&lt;br /&gt;
Assume you have created a nine-patch and added into res folder.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;// Lets load the drawable and get it&amp;nbsp;minimum&amp;nbsp;height,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;// here I am going to stretch horizontally so i get height.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;Drawable drawable = getResources().getDrawable(R.drawable.progress);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;int height = drawable.getMinimumHeight();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;// If you check, you can identify that the drawable will be NinePatchDrawable.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;// First lets examine how this nine patch getting drawn.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;// set the&amp;nbsp;boundary and pass the canvas to be drawn.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;drawable.setBounds(0, 0, getWidth(), height);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;drawable.draw(canvas);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;//this will draw the 0-100% progress bar.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;//Now let us try a clipped progress bar.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;//Create a clip drawable with above nine-patch, Gravity.LEFT , ClipDrawable.HORIZONTAL&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;ClipDrawable clipDrawable1 = new ClipDrawable(drawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;//Set the level 9000, this will draw the 90% of the left part.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;clipDrawable1.setLevel(9000);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;clipDrawable1.setBounds(0, height, getWidth(), 2*height);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;clipDrawable1.draw(canvas);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;//this will draw 0-90%&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;//Lets create another ClipDrawable which will draw 80% of right part.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;ClipDrawable clipDrawable2 = new ClipDrawable(clipDrawable1, Gravity.RIGHT, ClipDrawable.HORIZONTAL);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;clipDrawable2.setLevel(8000);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;clipDrawable2.setBounds(0, 2*height, getWidth(), 3*height);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;clipDrawable2.draw(canvas);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;//This draws 20%-80%&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;//But we expected this should draw 20%-90% progress bar.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;//But issue is above clipDrawable2.setLevel(8000) set level of both Drawable.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;//So set level of clipDrawable1 again and draw.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;clipDrawable1.setLevel(9000);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;clipDrawable2.setBounds(0, 3*height, getWidth(), 4*height);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;clipDrawable2.draw(canvas);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;//This will draw 20%-90% drawable.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Take, we can draw both sided progress bar using clip drawable one inside another, but set Level method will set all&amp;nbsp;children&#39;s level, so after setting parent level we have to set chid levels in that order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/3401820951862553201/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/3401820951862553201' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/3401820951862553201'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/3401820951862553201'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2012/07/android-drawing-both-side-clipped.html' title='Android: Drawing both side clipped  Progress Bar'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7awXl-1-3EvSBVvfPw2B5uWpo1N3Dvflw3f-siKwMO02CWEnDoPsns9Waez-45xKLs_DK2adc2axUvVTxL9v3uBglfA_xyXo4hCFMN9mZxdk6zWteXf8b7qlX3nSjVt_3YP-OQ_1dHLE/s72-c/image" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-5489099868046436090</id><published>2012-06-29T00:11:00.001-07:00</published><updated>2012-06-29T00:11:47.769-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="base line"/><category scheme="http://www.blogger.com/atom/ns#" term="text drawing"/><title type='text'>Android: Understating Text Drawing</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
When it comes to draw text inside our custom view, it is&amp;nbsp;difficult&amp;nbsp;to position text vertically in correct place if we use &lt;a href=&quot;http://developer.android.com/reference/android/graphics/Canvas.html#drawText(java.lang.String, float, float, android.graphics.Paint)&quot;&gt;canvas.drawText(..,x,y..)&amp;nbsp;&lt;/a&gt;, because it will not start to draw from the give y&amp;nbsp;coordinate rather it will position the text base line in the give y coordinate.&lt;br /&gt;
&lt;br /&gt;
First look at this following image:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHOp9j1e1Pb7uFK9_0iVVgWudZySOMI4pgfHD7gCjFlYm0cC_A9flMamxLNv3tMsuNeIx-cghbSIakHHtWkZwt5TQ5ByMdIAIEXz2PgXIJAi46tPYM-0IXD1Y0V3uUWo3MHk3YdbmLPKQ/s1600/text.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;315&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHOp9j1e1Pb7uFK9_0iVVgWudZySOMI4pgfHD7gCjFlYm0cC_A9flMamxLNv3tMsuNeIx-cghbSIakHHtWkZwt5TQ5ByMdIAIEXz2PgXIJAi46tPYM-0IXD1Y0V3uUWo3MHk3YdbmLPKQ/s400/text.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
In the first view (view 01) text&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;and a red line are&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;drawn in the middle vertically.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue; font-size: x-small; font-style: italic;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;background-color: white; color: blue; font-size: x-small; font-style: italic; white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-size: x-small; font-style: italic;&quot;&gt;TEXT_PAINT.setColor(Color.WHITE);&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//Drawing the text at middle of the view&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;canvas.drawText(LONG_STRING, 0, getHeight()/2, TEXT_PAINT);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;TEXT_PAINT.setColor(Color.RED);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;//Here we draw the middle line&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;canvas.drawLine(0, getHeight()/2, getWidth(), getHeight()/2, TEXT_PAINT);&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;If you think that, the text is drawn on top of the line, then simply if we find an API to get the height of the text then we can align use that value.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue; font-size: x-small; font-style: italic;&quot;&gt;Rect rect = new Rect();&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;TEXT_PAINT.setColor(Color.BLUE);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;TEXT_PAINT.getTextBounds(LONG_STRING, 0, LONG_STRING.length(), rect);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;//Measure the height and draw line on top of text&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;canvas.drawLine(0, getHeight()/2-rect.height(), getWidth(), getHeight()/2-rect.height(), TEXT_PAINT);&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
But that is not the case, you see, some part of &#39;&lt;span style=&quot;background-color: white;&quot;&gt;y&#39; from &#39;Please try this is...&#39; is drawn down of the middle line. So we want to know how actually text are drawn and actual center of the text.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;To understand this I used&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;a href=&quot;http://developer.android.com/reference/android/text/StaticLayout.html&quot;&gt;StaticLayout&lt;/a&gt;&amp;nbsp;in the second view (view 02).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue; font-size: x-small; font-style: italic;&quot;&gt;TEXT_PAINT.setColor(Color.WHITE);&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;//Create a static layout to draw&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;StaticLayout staticLayout = new StaticLayout(&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;LONG_STRING, 0, LONG_STRING.length(),&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;TEXT_PAINT,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;getWidth(),android.text.Layout.Alignment.ALIGN_CENTER ,&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;1.0f, 1.0f, false);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;staticLayout.draw(canvas);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;It provides necessary API to get top, bottom and base line of the text. In the second view you can see those lines.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue; font-size: x-small; font-style: italic;&quot;&gt;for(int i = 0 ; i &amp;lt; staticLayout.getLineCount();i++){&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;TEXT_PAINT.setColor(Color.BLUE);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;canvas.drawLine(0, staticLayout.getLineTop(i), getWidth(), staticLayout.getLineTop(i), TEXT_PAINT);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;TEXT_PAINT.setColor(0x7FFFFFFF&amp;amp;Color.YELLOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;canvas.drawRect(staticLayout.getLineLeft(i), staticLayout.getLineTop(i), staticLayout.getLineRight(i), staticLayout.getLineBottom(i), TEXT_PAINT);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;TEXT_PAINT.setColor(Color.RED);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;canvas.drawLine(0, staticLayout.getLineBaseline(i), getWidth(), staticLayout.getLineBaseline(i), TEXT_PAINT);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;TEXT_PAINT.setColor(Color.MAGENTA);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;canvas.drawLine(0, staticLayout.getLineBottom(i), getWidth(), staticLayout.getLineBottom(i), TEXT_PAINT);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: small; font-style: italic;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Now let use this values to draw text in proper place as shown in view 03.&lt;br /&gt;
&lt;i style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;canvas.drawText(LONG_STRING, 0, getHeight()/2+(staticLayout.getLineBaseline(0)-staticLayout.getLineBottom(0)/2), TEXT_PAINT);&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-style: italic;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;a href=&quot;http://dl.dropbox.com/u/7717254/DemoTextDrawing.zip&quot;&gt;I have uploaded sample source code here:&lt;/a&gt;&lt;br /&gt;
Thanks&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/5489099868046436090/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/5489099868046436090' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/5489099868046436090'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/5489099868046436090'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2012/06/android-understating-text-drawing.html' title='Android: Understating Text Drawing'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHOp9j1e1Pb7uFK9_0iVVgWudZySOMI4pgfHD7gCjFlYm0cC_A9flMamxLNv3tMsuNeIx-cghbSIakHHtWkZwt5TQ5ByMdIAIEXz2PgXIJAi46tPYM-0IXD1Y0V3uUWo3MHk3YdbmLPKQ/s72-c/text.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-8845282975351473815</id><published>2012-06-27T03:51:00.000-07:00</published><updated>2012-06-27T20:19:18.559-07:00</updated><title type='text'>Android: Play video on Top of GLSurfaceView</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
i modified the&amp;nbsp;GLSurfaceViewActivity from ApiDemo to check to see where can play Video on top of GLSurfaceView.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class GLSurfaceViewActivity extends Activity implements OnClickListener, OnCompletionListener, OnTouchListener {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@SuppressWarnings(&quot;unused&quot;)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private static final String TAG = &quot;com.example.android.apis.graphics.GLSurfaceViewActivity&quot;;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @Override&lt;br /&gt;
&amp;nbsp; &amp;nbsp; protected void onCreate(Bundle savedInstanceState) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super.onCreate(savedInstanceState);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Create our Preview view and set it as the content of our&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Activity&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mGLSurfaceView = new GLSurfaceView(this);&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mGLSurfaceView.setOnTouchListener(this);&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mGLSurfaceView.setRenderer(new CubeRenderer(false));&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FrameLayout frameLayout = new FrameLayout(this);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; frameLayout.addView(mGLSurfaceView, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,FrameLayout.LayoutParams.FILL_PARENT));&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mVideoView = new VideoView(this);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mVideoView.setVisibility(View.INVISIBLE);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mVideoView.setOnCompletionListener(this);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;frameLayout.addView(mVideoView, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,FrameLayout.LayoutParams.FILL_PARENT));&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mCheckBox = new CheckBox(this);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mCheckBox.setText(&quot;Load Video&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mCheckBox.setOnClickListener(this);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;frameLayout.addView(mCheckBox, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,FrameLayout.LayoutParams.WRAP_CONTENT,Gravity.CENTER));&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setContentView(frameLayout);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @Override&lt;br /&gt;
&amp;nbsp; &amp;nbsp; protected void onResume() {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Ideally a game should implement onResume() and onPause()&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // to take appropriate action when the activity looses focus&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super.onResume();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mGLSurfaceView.onResume();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @Override&lt;br /&gt;
&amp;nbsp; &amp;nbsp; protected void onPause() {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Ideally a game should implement onResume() and onPause()&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // to take appropriate action when the activity looses focus&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super.onPause();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mGLSurfaceView.onPause();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; private GLSurfaceView mGLSurfaceView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private VideoView mVideoView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private CheckBox mCheckBox;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public void onClick(View arg0) {&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(mCheckBox.isChecked()){&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;Intent intent = new Intent(Intent.ACTION_GET_CONTENT);&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;intent.setType(&quot;video/*&quot;);&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;startActivityForResult(Intent.createChooser(intent, &quot;Chose a Video&quot;), 10);&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}else{&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;mVideoView.setVisibility(View.VISIBLE);&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;mVideoView.start();&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;mCheckBox.setChecked(true);&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;protected void onActivityResult(int requestCode, int resultCode, Intent data) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(data!=null &amp;amp;&amp;amp; data.getData()!=null){&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;mCheckBox.setText(&quot;Play Video&quot;);&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;mVideoView.setVideoURI(data.getData());&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;mVideoView.setVisibility(View.VISIBLE);&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;mVideoView.start();&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}else{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;mCheckBox.setChecked(false);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;super.onActivityResult(requestCode, resultCode, data);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public void onCompletion(MediaPlayer arg0) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;mVideoView.setVisibility(View.INVISIBLE);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Override&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public boolean onTouch(View view, MotionEvent motionEvent) {&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;mVideoView.setTranslationX(motionEvent.getX());&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;mVideoView.setTranslationY(motionEvent.getY());&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return true;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/8845282975351473815/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/8845282975351473815' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/8845282975351473815'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/8845282975351473815'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2012/06/android-play-video-on-top-of.html' title='Android: Play video on Top of GLSurfaceView'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-8602789187304140540</id><published>2012-06-26T23:59:00.001-07:00</published><updated>2012-06-26T23:59:21.913-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Logging"/><title type='text'>Logging Caller Method Info in Java</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In our application, one method maybe called from multiple locations. While debugging application we may need to log it caller caller method information in those case following line will be use full.&lt;br /&gt;
Here from the current thread, I get called Stack and print that for us.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;void&lt;/span&gt; someMethod() {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;System.&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;out&lt;/span&gt;.println(Thread.currentThread().getStackTrace()[0]);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;System.&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;out&lt;/span&gt;.println(Thread.currentThread().getStackTrace()[1]);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;System.&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;out&lt;/span&gt;.println(Thread.currentThread().getStackTrace()[2]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&lt;i&gt;java.lang.Thread.getStackTrace(Thread.java:1479)&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&lt;i&gt;demo.TestThread.someMethod(TestThread.java:14)&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&lt;i&gt;demo.TestThread.main(TestThread.java:9)&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
What we want from this output is &lt;b style=&quot;font-style: italic;&quot;&gt;&quot;demo.TestThread.main(TestThread.java:9)&quot; &lt;/b&gt;So you use in your java application.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;System.&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;out&lt;/span&gt;.println(Thread.currentThread().getStackTrace()[&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red; font-size: large;&quot;&gt;2&lt;/span&gt;]);&amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
Okey for Android Application I try followings:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;void&lt;/span&gt; onCreate(Bundle savedInstanceState) {&lt;br /&gt;
..................&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Log.i(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;TAG&lt;/span&gt;, &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&quot;::onCreate:&quot;&lt;/span&gt; +Thread.currentThread().getStackTrace()[0]);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Log.i(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;TAG&lt;/span&gt;, &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&quot;::onCreate:&quot;&lt;/span&gt; +Thread.currentThread().getStackTrace()[1]);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Log.i(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;TAG&lt;/span&gt;, &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&quot;::onCreate:&quot;&lt;/span&gt; +Thread.currentThread().getStackTrace()[2]);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Log.i(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;TAG&lt;/span&gt;, &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&quot;::onCreate:&quot;&lt;/span&gt; +Thread.currentThread().getStackTrace()[3]);&lt;br /&gt;
&lt;br /&gt;
............&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&lt;i&gt;onCreate:dalvik.system.VMStack.getThreadStackTrace(Native Method)&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&lt;i&gt;onCreate:java.lang.Thread.getStackTrace(Thread.java:591)&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&lt;i&gt;onCreate:demo.multi.line.text.DemoMultiLineTextActivity.onCreate(DemoMultiLineTextActivity.java:58)&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&lt;i&gt;onCreate:android.app.Activity.performCreate(Activity.java:4518)&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
What we want from this output is &quot;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&lt;i&gt;onCreate:android.app.Activity.performCreate(Activity.java:4518)&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&quot; So you use in your Android application:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Log.i(TAG,&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&quot;::onCreate:&quot;&lt;/span&gt;&amp;nbsp;+Thread.currentThread().getStackTrace()[&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red; font-size: large;&quot;&gt;3&lt;/span&gt;]);&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/8602789187304140540/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/8602789187304140540' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/8602789187304140540'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/8602789187304140540'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2012/06/logging-caller-method-info-in-java.html' title='Logging Caller Method Info in Java'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-5042776184449135404</id><published>2012-06-22T09:13:00.001-07:00</published><updated>2012-06-27T02:55:38.212-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="grid view"/><title type='text'>Android: Bigger Image for any of the Image inside Grid View</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
As and&amp;nbsp;extension for my&amp;nbsp;earlier&amp;nbsp;&lt;a href=&quot;http://sudarnimalan.blogspot.sg/2012/06/android-bigger-image-for-first-item-of.html&quot;&gt;post&lt;/a&gt;, I have created the project to apply for any of the image in the grid and it will support for any number of columns and the bigger image and can take any number of column with.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqnyXut7EahqOodnC3bQxzJETs3VGbJgjk6UD5ItjDW3FpJ8POLR4-TL59RrT8izYdho3CumhKHBtQ7nLwIpjS_AwMu7jTP52_Ab_nNtFiwbfeZDnnpOzdUINnoiShhfq_IhNCCZ7AlAI/s1600/device-2012-06-23-113452.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqnyXut7EahqOodnC3bQxzJETs3VGbJgjk6UD5ItjDW3FpJ8POLR4-TL59RrT8izYdho3CumhKHBtQ7nLwIpjS_AwMu7jTP52_Ab_nNtFiwbfeZDnnpOzdUINnoiShhfq_IhNCCZ7AlAI/s200/device-2012-06-23-113452.png&quot; width=&quot;120&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3PhP2-SDdjAgdX_17feG-Dm0DJy9_MTzfen3Uw3mKsdx0VoseFYh5OezsA7rPnIgNlVORgOGwdaQb17wKsygE1gI_h4W80_hcShccvDi-mR9kE29Bjkac8-1Wzja9UuRgq4s146pIc80/s1600/device-2012-06-23-113552.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3PhP2-SDdjAgdX_17feG-Dm0DJy9_MTzfen3Uw3mKsdx0VoseFYh5OezsA7rPnIgNlVORgOGwdaQb17wKsygE1gI_h4W80_hcShccvDi-mR9kE29Bjkac8-1Wzja9UuRgq4s146pIc80/s200/device-2012-06-23-113552.png&quot; width=&quot;120&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrCcAgsOC95Hk-mz_ESwfXoDt65SRZjZf7wjK5AZz7UL0u7cV504BMGVE9qk99o9NgQ4-PCUKELhgxLsLJD6ZTexRU_u2t4NPPYBthggQgpoSgf1xSyzmkGOJZXnLI6rRpFs2niZAWYec/s1600/device-2012-06-23-113622.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrCcAgsOC95Hk-mz_ESwfXoDt65SRZjZf7wjK5AZz7UL0u7cV504BMGVE9qk99o9NgQ4-PCUKELhgxLsLJD6ZTexRU_u2t4NPPYBthggQgpoSgf1xSyzmkGOJZXnLI6rRpFs2niZAWYec/s200/device-2012-06-23-113622.png&quot; width=&quot;120&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1DMhU7PSeO5FxqUF6W6RVWykpQ0JKsAdQAjO3-MZB2gXJY1bJx_urxWPdskYS-SiWvGGGKzMMFJoOfJwZ0oEh9XX3pDHedMAZt5-CdnB8LgEwdKElT4KdZ8O-_-qZdCVQ26akEQaTtOo/s1600/device-2012-06-23-113639.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1DMhU7PSeO5FxqUF6W6RVWykpQ0JKsAdQAjO3-MZB2gXJY1bJx_urxWPdskYS-SiWvGGGKzMMFJoOfJwZ0oEh9XX3pDHedMAZt5-CdnB8LgEwdKElT4KdZ8O-_-qZdCVQ26akEQaTtOo/s200/device-2012-06-23-113639.png&quot; width=&quot;120&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOkvJY-i5zibUYqc07GMBjtTyBgWV5uFujK0rzIfODf32NnMRC_d9VjOw9SgIvwOAawtEdgR9FoA8834YyPqdx3ONcsnREjnOaaQc_R9if1liEu0QCs9Om9mwqC_LrIG2BmaA_u8bqoFc/s1600/device-2012-06-23-113659.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOkvJY-i5zibUYqc07GMBjtTyBgWV5uFujK0rzIfODf32NnMRC_d9VjOw9SgIvwOAawtEdgR9FoA8834YyPqdx3ONcsnREjnOaaQc_R9if1liEu0QCs9Om9mwqC_LrIG2BmaA_u8bqoFc/s200/device-2012-06-23-113659.png&quot; width=&quot;120&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsFbY2w2dNs_2UxCmC73sKW3YOeDie0Q-iBNq0JRESn8LGG9-gNsgaBw99Q4o4bpaVHhS5XL0sjIvQhzLS6UNNzxb_NfoLpdcphXPAuM-YCnG8BVJxmeUKbb5UE0CJp_utujqKjc0dTGo/s1600/device-2012-06-23-113710.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsFbY2w2dNs_2UxCmC73sKW3YOeDie0Q-iBNq0JRESn8LGG9-gNsgaBw99Q4o4bpaVHhS5XL0sjIvQhzLS6UNNzxb_NfoLpdcphXPAuM-YCnG8BVJxmeUKbb5UE0CJp_utujqKjc0dTGo/s200/device-2012-06-23-113710.png&quot; width=&quot;120&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
I have uploaded the&lt;a href=&quot;http://dl.dropbox.com/u/7717254/DemoGridView_02.zip&quot;&gt; source code&lt;/a&gt; here:&amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://dl.dropbox.com/u/7717254/DemoGridView_02.zip&quot;&gt;http://dl.dropbox.com/u/7717254/DemoGridView_02.zip&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
But if you have bigger image column size if greater than half of the grid column size it has some bug, and need to fix that first.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/5042776184449135404/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/5042776184449135404' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/5042776184449135404'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/5042776184449135404'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2012/06/android-bigger-image-for-any-of-image.html' title='Android: Bigger Image for any of the Image inside Grid View'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqnyXut7EahqOodnC3bQxzJETs3VGbJgjk6UD5ItjDW3FpJ8POLR4-TL59RrT8izYdho3CumhKHBtQ7nLwIpjS_AwMu7jTP52_Ab_nNtFiwbfeZDnnpOzdUINnoiShhfq_IhNCCZ7AlAI/s72-c/device-2012-06-23-113452.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-3640013929555314666</id><published>2012-06-20T04:58:00.000-07:00</published><updated>2012-06-22T09:15:34.667-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="grid view"/><title type='text'>Android: Bigger image for first item of the gridview</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Say you want layout like below:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAnmlOGWQ3XQZaimLDyymvm5W7RvibMfEoEVMaiDocnaDiHtoxD5In9fMipzcfnhqkvn1BF38OvayUMMrvfk8ZZDbacxAcshSkjNggxCVaLxalpXHN-KkjHF3RqAuhX2tRimimuep1ILI/s1600/screen.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAnmlOGWQ3XQZaimLDyymvm5W7RvibMfEoEVMaiDocnaDiHtoxD5In9fMipzcfnhqkvn1BF38OvayUMMrvfk8ZZDbacxAcshSkjNggxCVaLxalpXHN-KkjHF3RqAuhX2tRimimuep1ILI/s320/screen.jpg&quot; width=&quot;201&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
I start to implement with following XML , activity,&amp;nbsp;adapter:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;br /&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; android:layout_height=&quot;fill_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; android:orientation=&quot;vertical&quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;GridView&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/gridView1&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;match_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;match_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:numColumns=&quot;5&quot; &amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/GridView&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/LinearLayout&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
package demo.grid.view;&lt;br /&gt;
&lt;br /&gt;
import android.app.Activity;&lt;br /&gt;
import android.graphics.Bitmap;&lt;br /&gt;
import android.graphics.BitmapFactory;&lt;br /&gt;
import android.graphics.Color;&lt;br /&gt;
import android.os.Bundle;&lt;br /&gt;
import android.view.View;&lt;br /&gt;
import android.view.ViewGroup;&lt;br /&gt;
import android.widget.BaseAdapter;&lt;br /&gt;
import android.widget.GridView;&lt;br /&gt;
import android.widget.ImageView;&lt;br /&gt;
import android.widget.ImageView.ScaleType;&lt;br /&gt;
&lt;br /&gt;
public class DemoGridViewActivity extends Activity {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; /** Called when the activity is first created. */&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @Override&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super.onCreate(savedInstanceState);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setContentView(R.layout.main);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GridView gridView = (GridView)findViewById(R.id.gridView1);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gridView.setAdapter(new GridViewAdaptor());&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; class GridViewAdaptor extends BaseAdapter{&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;public int getCount() {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return 50;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;public Object getItem(int arg0) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return arg0;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;public long getItemId(int arg0) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return arg0;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;public View getView(int arg0, View arg1, ViewGroup arg2) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;ImageView imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;if(arg1==null){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView = new ImageView(DemoGridViewActivity.this){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;protected void onMeasure(int widthMeasureSpec,&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;int heightMeasureSpec) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;super.onMeasure(widthMeasureSpec, heightMeasureSpec);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;};&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}else{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView = (ImageView) arg1;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;imageView.setLayoutParams(new GridView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;imageView.setBackgroundColor(Color.BLUE);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;imageView.setScaleType(ScaleType.FIT_XY);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;switch(arg0){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 0:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setImageBitmap(Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth()/2, bitmap.getHeight()/2));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setBackgroundColor(Color.RED);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 1:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setImageBitmap(Bitmap.createBitmap(bitmap, bitmap.getWidth()/2, 0, bitmap.getWidth()/2, bitmap.getHeight()/2));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setBackgroundColor(Color.GREEN);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 5:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setImageBitmap(Bitmap.createBitmap(bitmap, 0, bitmap.getHeight()/2, bitmap.getWidth()/2, bitmap.getHeight()/2));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setBackgroundColor(Color.YELLOW);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 6:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setImageBitmap(Bitmap.createBitmap(bitmap, bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2, bitmap.getHeight()/2));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setBackgroundColor(Color.MAGENTA);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;default:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setImageResource(R.drawable.ic_launcher);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizHIPd-Pcet_z-aUp3hfIxcjx61hzlyaAU4-K880v3AeSQfvXZA2F0N22KG91z7gGUd3NMJSFV_jhtw2rINS6q0g9prmT2rxirgGCfrzGU4fxy7fZOSHi-7ueAyQeNBhlOaKeJvxCGF4o/s1600/screen02.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizHIPd-Pcet_z-aUp3hfIxcjx61hzlyaAU4-K880v3AeSQfvXZA2F0N22KG91z7gGUd3NMJSFV_jhtw2rINS6q0g9prmT2rxirgGCfrzGU4fxy7fZOSHi-7ueAyQeNBhlOaKeJvxCGF4o/s320/screen02.jpg&quot; width=&quot;201&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Now this issue is how to work with a list of object and translate it into this grid view. Following translation needed to be done for adapter:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;public int getCount() {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return integers.size()+3;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;switch(arg0){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 0:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setTag(integers.get(0));&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 1:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setTag(integers.get(0));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 5:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setTag(integers.get(0));&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 6:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setTag(integers.get(0));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;default:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if(arg0&amp;gt;1 &amp;amp;&amp;amp; arg0&amp;lt;=4){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;imageView.setTag(integers.get(arg0-1));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}else{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;imageView.setTag(integers.get(arg0-3));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
full code is here:&lt;br /&gt;
&lt;br /&gt;
package demo.grid.view;&lt;br /&gt;
&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import android.app.Activity;&lt;br /&gt;
import android.graphics.Bitmap;&lt;br /&gt;
import android.graphics.BitmapFactory;&lt;br /&gt;
import android.graphics.Canvas;&lt;br /&gt;
import android.graphics.Color;&lt;br /&gt;
import android.graphics.Paint;&lt;br /&gt;
import android.os.Bundle;&lt;br /&gt;
import android.view.View;&lt;br /&gt;
import android.view.ViewGroup;&lt;br /&gt;
import android.widget.BaseAdapter;&lt;br /&gt;
import android.widget.GridView;&lt;br /&gt;
import android.widget.ImageView;&lt;br /&gt;
import android.widget.ImageView.ScaleType;&lt;br /&gt;
&lt;br /&gt;
public class DemoGridViewActivity extends Activity {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; /** Called when the activity is first created. */&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;List&lt;integer&gt; integers = new ArrayList&lt;integer&gt;();&lt;/integer&gt;&lt;/integer&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @Override&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super.onCreate(savedInstanceState);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setContentView(R.layout.main);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(int i = 0 ; i &amp;lt; 50 ; i++){&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;integers.add(i);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GridView gridView = (GridView)findViewById(R.id.gridView1);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gridView.setAdapter(new GridViewAdaptor());&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; class GridViewAdaptor extends BaseAdapter{&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;public int getCount() {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return integers.size()+3;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;public Object getItem(int arg0) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return arg0;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;public long getItemId(int arg0) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return arg0;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;public View getView(int arg0, View arg1, ViewGroup arg2) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;ImageView imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;if(arg1==null){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView = new ImageView(DemoGridViewActivity.this){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;protected void onMeasure(int widthMeasureSpec,&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;int heightMeasureSpec) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;super.onMeasure(widthMeasureSpec, heightMeasureSpec);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;protected void onDraw(Canvas canvas) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;super.onDraw(canvas);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;Paint paint = new Paint();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;paint.setColor(Color.RED);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;paint.setTextSize(36);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;canvas.drawText(getTag().toString(), getWidth()/2, getHeight()/2, paint);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;};&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}else{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView = (ImageView) arg1;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;imageView.setLayoutParams(new GridView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;imageView.setBackgroundColor(Color.BLUE);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;imageView.setScaleType(ScaleType.FIT_XY);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;switch(arg0){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 0:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setImageBitmap(Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth()/2, bitmap.getHeight()/2));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setBackgroundColor(Color.RED);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setTag(integers.get(0));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 1:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setImageBitmap(Bitmap.createBitmap(bitmap, bitmap.getWidth()/2, 0, bitmap.getWidth()/2, bitmap.getHeight()/2));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setBackgroundColor(Color.GREEN);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setTag(integers.get(0));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 5:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setImageBitmap(Bitmap.createBitmap(bitmap, 0, bitmap.getHeight()/2, bitmap.getWidth()/2, bitmap.getHeight()/2));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setBackgroundColor(Color.YELLOW);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setTag(integers.get(0));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 6:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setImageBitmap(Bitmap.createBitmap(bitmap, bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2, bitmap.getHeight()/2));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setBackgroundColor(Color.MAGENTA);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setTag(integers.get(0));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;default:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if(arg0&amp;gt;1 &amp;amp;&amp;amp; arg0&amp;lt;=4){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;imageView.setTag(integers.get(arg0-1));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}else{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;imageView.setTag(integers.get(arg0-3));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setImageResource(R.drawable.ic_launcher);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHLd3CJ1dkmepSJQV3y-6gSz_8DhhvTpIhvRu8ydTXvA3TaNliLInB1SA3Hf6pEWNdFCCDRpL12PidaYUMqBAd-1_dAK1bd5Gv8JYm3jJUKwPmSfMnuLYrdoK_8k-g4gULa1dIUNNVgmk/s1600/screen03.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHLd3CJ1dkmepSJQV3y-6gSz_8DhhvTpIhvRu8ydTXvA3TaNliLInB1SA3Hf6pEWNdFCCDRpL12PidaYUMqBAd-1_dAK1bd5Gv8JYm3jJUKwPmSfMnuLYrdoK_8k-g4gULa1dIUNNVgmk/s320/screen03.jpg&quot; width=&quot;202&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
finally this code for loading images from device sdcard and display in the gridview:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
package demo.grid.view;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
import android.app.Activity;&lt;br /&gt;
import android.app.Dialog;&lt;br /&gt;
import android.app.ProgressDialog;&lt;br /&gt;
import android.database.Cursor;&lt;br /&gt;
import android.graphics.Bitmap;&lt;br /&gt;
import android.graphics.Color;&lt;br /&gt;
import android.os.AsyncTask;&lt;br /&gt;
import android.os.Bundle;&lt;br /&gt;
import android.provider.MediaStore;&lt;br /&gt;
import android.provider.MediaStore.Images.Thumbnails;&lt;br /&gt;
import android.view.View;&lt;br /&gt;
import android.view.ViewGroup;&lt;br /&gt;
import android.widget.BaseAdapter;&lt;br /&gt;
import android.widget.GridView;&lt;br /&gt;
import android.widget.ImageView;&lt;br /&gt;
import android.widget.ImageView.ScaleType;&lt;br /&gt;
public class DemoGridViewActivity extends Activity {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; private static final int START_PROGRESS = 10;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;List&lt;bitmap&gt; mBitmaps = new ArrayList&lt;bitmap&gt;();&lt;/bitmap&gt;&lt;/bitmap&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @Override&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super.onCreate(savedInstanceState);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setContentView(R.layout.main);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AsyncTask&lt;void, void,=&quot;&quot; void=&quot;&quot;&gt; asyncTask = new AsyncTask&lt;void, void,=&quot;&quot; void=&quot;&quot;&gt;(){&lt;/void,&gt;&lt;/void,&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Override&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;protected void onPreExecute() {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;showDialog(START_PROGRESS);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;super.onPreExecute();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;protected Void doInBackground(Void... params) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;Cursor query = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Images.Media._ID}, null, null, null);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if(query!=null &amp;amp;&amp;amp; query.moveToFirst()){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;do{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;int columnIndex = query.getColumnIndex(MediaStore.Images.Media._ID);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;long origId = query.getLong(columnIndex);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;mBitmaps.add(MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), origId, Thumbnails.MICRO_KIND, null));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;}while(query.moveToNext());&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;query.close();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return null;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;protected void onPostExecute(Void result) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;removeDialog(START_PROGRESS);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;GridView gridView = (GridView)findViewById(R.id.gridView1);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;gridView.setAdapter(new GridViewAdaptor());&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;super.onPostExecute(result);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; };&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; asyncTask.execute();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @Override&lt;br /&gt;
&amp;nbsp; &amp;nbsp; protected Dialog onCreateDialog(int id, Bundle args) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return new ProgressDialog(this);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; class GridViewAdaptor extends BaseAdapter{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;public int getCount() {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return mBitmaps.size()+3;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;public Object getItem(int arg0) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return arg0;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;public long getItemId(int arg0) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return arg0;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;public View getView(int arg0, View arg1, ViewGroup arg2) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;ImageView imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;if(arg1==null){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView = new ImageView(DemoGridViewActivity.this){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;protected void onMeasure(int widthMeasureSpec,&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;int heightMeasureSpec) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;super.onMeasure(widthMeasureSpec, heightMeasureSpec);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;};&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}else{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView = (ImageView) arg1;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;imageView.setLayoutParams(new GridView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;imageView.setBackgroundColor(Color.BLUE);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;imageView.setScaleType(ScaleType.FIT_XY);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;Bitmap bitmap;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;switch(arg0){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 0:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setPadding(10, 10, 0, 0);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;bitmap = mBitmaps.get(0);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setImageBitmap(Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth()/2, bitmap.getHeight()/2));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setBackgroundColor(Color.RED);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 1:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setPadding(0, 10, 10, 0);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;bitmap = mBitmaps.get(0);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setImageBitmap(Bitmap.createBitmap(bitmap, bitmap.getWidth()/2, 0, bitmap.getWidth()/2, bitmap.getHeight()/2));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setBackgroundColor(Color.GREEN);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 5:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setPadding(10, 0, 0, 10);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;bitmap = mBitmaps.get(0);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setImageBitmap(Bitmap.createBitmap(bitmap, 0, bitmap.getHeight()/2, bitmap.getWidth()/2, bitmap.getHeight()/2));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setBackgroundColor(Color.YELLOW);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;case 6:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setPadding(0, 0, 10, 10);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;bitmap = mBitmaps.get(0);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setImageBitmap(Bitmap.createBitmap(bitmap, bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2, bitmap.getHeight()/2));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setBackgroundColor(Color.MAGENTA);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;default:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if(arg0&amp;gt;1 &amp;amp;&amp;amp; arg0&amp;lt;=4){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;bitmap = mBitmaps.get(arg0-1);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}else{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;bitmap = mBitmaps.get(arg0-3);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setPadding(10, 10, 10, 10);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;imageView.setImageBitmap(bitmap);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;return imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
here you have sample code:&amp;nbsp;&lt;a href=&quot;http://dl.dropbox.com/u/7717254/DemoGridView.zip&quot;&gt;source code&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
please check this &lt;a href=&quot;http://sudarnimalan.blogspot.sg/2012/06/android-bigger-image-for-any-of-image.html&quot;&gt;post&lt;/a&gt; for more update:&amp;nbsp;&lt;a href=&quot;http://sudarnimalan.blogspot.sg/2012/06/android-bigger-image-for-any-of-image.html&quot;&gt;http://sudarnimalan.blogspot.sg/2012/06/android-bigger-image-for-any-of-image.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/3640013929555314666/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/3640013929555314666' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/3640013929555314666'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/3640013929555314666'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2012/06/android-bigger-image-for-first-item-of.html' title='Android: Bigger image for first item of the gridview'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAnmlOGWQ3XQZaimLDyymvm5W7RvibMfEoEVMaiDocnaDiHtoxD5In9fMipzcfnhqkvn1BF38OvayUMMrvfk8ZZDbacxAcshSkjNggxCVaLxalpXHN-KkjHF3RqAuhX2tRimimuep1ILI/s72-c/screen.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-7471316359596627964</id><published>2012-06-19T00:43:00.002-07:00</published><updated>2014-04-16T18:57:18.965-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="eclipse"/><category scheme="http://www.blogger.com/atom/ns#" term="templates"/><title type='text'>Part1 : Useful Eclipse Templates for Android Development</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I normally setup eclipse templates for&amp;nbsp;repeat&amp;nbsp;coding fragments. If you are not aware of eclipse editor templates, just a small example: just open a java code file and type&lt;b&gt; &quot;syso&quot; (shortcut name)&lt;/b&gt; and press &lt;b&gt;Ctrl+space&lt;/b&gt; then you will see all &amp;nbsp;&quot;&lt;b&gt;System.out.println();&quot;&lt;/b&gt; will be inserted by eclipse for you.&lt;br /&gt;
To see all&amp;nbsp;existing templates and its shortcut open your eclipse, open the window menu and click on&amp;nbsp;Preference. Inside the&amp;nbsp;Preference dialog ,&amp;nbsp;navigate&amp;nbsp;to Java --&amp;gt; Editor --&amp;gt; Templates, Now you see full list there. &lt;b&gt;(Eclipse--&amp;gt;Window--&amp;gt;Preference--&amp;gt;Java--&amp;gt;Editor--&amp;gt;Templates)&lt;/b&gt;&lt;br /&gt;
You can add your own templates there and make use of them in your coding and make your coding fast. Just click &lt;b&gt;&quot;New..&quot; &lt;/b&gt;button, fill the &quot;&lt;b&gt;New&amp;nbsp;Template&quot;&lt;/b&gt;&amp;nbsp;Dialog&amp;nbsp;and OK.&lt;br /&gt;
&lt;br /&gt;
1. In android, in case if we want to get logs we want to insert &quot;&lt;b&gt;Log.i&quot;&lt;/b&gt; statements with proper message. This template will be useful for that.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Name: alog&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Context: Java statements&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Description: android log statement&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Pattern:&amp;nbsp;Log.i(TAG,&quot;::${enclosing_method}:&quot;+&quot;${cursor}&quot;);&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Now,For Example, in side onCreate &amp;nbsp;if you type alog and press Ctrl+space you will get:&lt;br /&gt;
&lt;b&gt;Log.i(TAG, &quot;::onCreate:&quot; + &quot;&quot;);&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
2. In #1 you see, we have to pass a TAG, normally this should be the Class name of the method we define in the top. I used to go for a full&amp;nbsp;qualified&amp;nbsp;name of any class. Sometime this will be useful in case of Custom Views to copy its name to crate layout XML files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Name:&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;atag&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;Context: Java type members&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Description:&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;android log tag&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;Pattern:&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;@SuppressWarnings(&quot;unused&quot;)&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;private static final String TAG = &quot;${enclosing_package}.${enclosing_type}&quot;;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ex:&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@SuppressWarnings(&quot;unused&quot;)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private static final String TAG = &quot;demo.DemoAcitity&quot;;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Inside the activity most we have to find View By Id and call some method on it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Name:&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;afind&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;Context: Java&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Description:&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;android find view&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;Pattern:&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;${type} ${new_name} = (${type})findViewById(R.id.${cursor});&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
type afind and press Ctrl+Space, then you will get:&lt;br /&gt;
&lt;span style=&quot;background-color: #9fc5e8;&quot;&gt;type|&lt;/span&gt; new_name = (&lt;span style=&quot;background-color: #cfe2f3;&quot;&gt;type&lt;/span&gt;)findViewById(R.id.);&lt;br /&gt;
&lt;br /&gt;
for example if that is a button then, type Button or But and press Ctrl+Space then you will get:&lt;br /&gt;
&lt;span style=&quot;background-color: #6fa8dc;&quot;&gt;Button&lt;/span&gt; new_name = (&lt;span style=&quot;background-color: #9fc5e8;&quot;&gt;Button&lt;/span&gt;)findViewById(R.id.);&lt;br /&gt;
&lt;br /&gt;
Then press Tab cursor will move to new_name&lt;br /&gt;
Button &lt;span style=&quot;background-color: #6fa8dc;&quot;&gt;new_name&lt;/span&gt; = (Button)findViewById(R.id.);&lt;br /&gt;
&lt;br /&gt;
Type the name you want for the variable, then press Tab cursor will move after &quot;.id.&quot;:&lt;br /&gt;
Button button = (Button)findViewById(R.id.&lt;span style=&quot;color: #3d85c6;&quot;&gt;|&lt;/span&gt;);&lt;br /&gt;
The just press Ctrl+space and choose the id from the list.&lt;br /&gt;
&lt;br /&gt;
So you will end as follows:&lt;br /&gt;
&lt;b&gt;Button button = (Button)findViewById(R.id.btn_add);&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In android we mostly do this in onCreate method and assign to member variable. and&amp;nbsp;refer from other method. Now you right click on the variable name choose Refactor&amp;nbsp;&amp;nbsp;and choose &quot;Convert Local Variable to&amp;nbsp;Field&quot; this will create a&amp;nbsp;Field&amp;nbsp;for you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://dl.dropbox.com/u/7717254/templates.xml&quot;&gt;here i have uploaded the template file.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://sudarnimalan.blogspot.sg/2013/01/part-2useful-eclipse-templates-for.html&quot;&gt;Part 2 :&amp;nbsp;Useful Eclipse Templates for Android Development&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/7471316359596627964/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/7471316359596627964' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/7471316359596627964'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/7471316359596627964'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2012/06/useful-eclipse-templates-for-android.html' title='Part1 : Useful Eclipse Templates for Android Development'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-6578880688261297974</id><published>2012-06-18T23:03:00.001-07:00</published><updated>2012-06-27T02:59:34.553-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="Liner Layout"/><title type='text'>Android: LinearLayout, Dynamically Arranging Views</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Let see how to&amp;nbsp;arrange buttons according to the user selection as shown below:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH5B1ou4CvgDIaVIK1X7uilNmGjsKFdZRgV4-vXvvPdccC0ZkHN7junZimoyRrvp-a7PzEav0AXOafnl2O3X12pjNHX-PzrZCoL2wasxb-vxkvwgRJsbCD1Dfe9nM8WvTtti5oL-RbWSg/s1600/device-2011-10-07-220804.png&quot; imageanchor=&quot;1&quot; style=&quot;display: inline !important; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH5B1ou4CvgDIaVIK1X7uilNmGjsKFdZRgV4-vXvvPdccC0ZkHN7junZimoyRrvp-a7PzEav0AXOafnl2O3X12pjNHX-PzrZCoL2wasxb-vxkvwgRJsbCD1Dfe9nM8WvTtti5oL-RbWSg/s200/device-2011-10-07-220804.png&quot; width=&quot;150&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMYVSbdAGDwua2DyW3kv4CQwibBINKTSe92_qvaK34Dscs4O4WnvETZNPkbWScxbuIKGIXuaN7PbwlaZRvaXyPbEQ_SgKwWLElEQbfqLrn2nXSNHcy9dcMiHJ-0hZg-xIDMq8-h-PnUqI/s1600/device-2011-10-07-220820.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMYVSbdAGDwua2DyW3kv4CQwibBINKTSe92_qvaK34Dscs4O4WnvETZNPkbWScxbuIKGIXuaN7PbwlaZRvaXyPbEQ_SgKwWLElEQbfqLrn2nXSNHcy9dcMiHJ-0hZg-xIDMq8-h-PnUqI/s200/device-2011-10-07-220820.png&quot; width=&quot;150&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUGgtj0g0lKtZvTnWk1rloqMVGvobW_Sh3-iVqq8FlYwp-amiRY2Cu_Y3xVILj3xqWpMG_gH14oSm9rPJBstxNPSBzzui18xBPyjx7ZUZlKByWqBFKZ2Kxo3d_m_QhLw7Kfmu8MYJRikU/s1600/device-2011-10-07-220828.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUGgtj0g0lKtZvTnWk1rloqMVGvobW_Sh3-iVqq8FlYwp-amiRY2Cu_Y3xVILj3xqWpMG_gH14oSm9rPJBstxNPSBzzui18xBPyjx7ZUZlKByWqBFKZ2Kxo3d_m_QhLw7Kfmu8MYJRikU/s200/device-2011-10-07-220828.png&quot; width=&quot;150&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;LinearLayout&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;android:orientation&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&quot;vertical&quot;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;android:id&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&quot;@+id/linearLayout1&quot;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;android:layout_height&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;fill_parent&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:layout_width&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;fill_parent&quot;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:text&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;Button&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:id&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;@+id/button0&quot;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;android:layout_height&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;fill_parent&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:layout_width&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;fill_parent&quot;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_weight&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;span class=&quot;s2&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:text&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;Button&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:id&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;@+id/button1&quot;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt; android:layout_height&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;fill_parent&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:layout_width&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;fill_parent&quot;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_weight&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:visibility&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;gone&quot;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;span class=&quot;s2&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:text&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;Button&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:id&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;@+id/button2&quot;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt; &lt;b&gt;android:layout_height&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;fill_parent&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:layout_weight&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;fill_parent&quot;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:visibility&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;gone&quot;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;span class=&quot;s2&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s1&quot;&gt;LinearLayout&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;Following java code would change the visibility according to the user selection.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
@Override&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;void&lt;/span&gt;&lt;/span&gt; onCheckedChanged(RadioGroup group, &lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; checkedId) {&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;switch&lt;/span&gt;(group.getCheckedRadioButtonId()){&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;case&lt;/span&gt;&lt;/span&gt; R.id.&lt;span class=&quot;s2&quot;&gt;radio0&lt;/span&gt;:&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button0&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;VISIBLE&lt;/span&gt;);&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button1&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;GONE&lt;/span&gt;);&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button2&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;GONE&lt;/span&gt;);&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;case&lt;/span&gt;&lt;/span&gt; R.id.&lt;span class=&quot;s2&quot;&gt;radio1&lt;/span&gt;:&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button0&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;VISIBLE&lt;/span&gt;);&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button1&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;VISIBLE&lt;/span&gt;);&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button2&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;GONE&lt;/span&gt;);&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;case&lt;/span&gt;&lt;/span&gt; R.id.&lt;span class=&quot;s2&quot;&gt;radio2&lt;/span&gt;:&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button0&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;VISIBLE&lt;/span&gt;);&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button1&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;VISIBLE&lt;/span&gt;);&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button2&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;VISIBLE&lt;/span&gt;);&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
}&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;Let see if we want a layout to change as show below:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNIRyrZ3amMvkjKfgkTLl9A0pGT2QRItM6ah9FBbauHVM4UI4mB9-cPo1Jb-Yj7J5stC2fIiqipqA-6NY-zOXLS_jsEdsFFwtI3rxw0Ae1krJZnmIO3z_v-vXdlVnpIq0sk6Io8pb1moE/s1600/device-2011-10-08-083106.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNIRyrZ3amMvkjKfgkTLl9A0pGT2QRItM6ah9FBbauHVM4UI4mB9-cPo1Jb-Yj7J5stC2fIiqipqA-6NY-zOXLS_jsEdsFFwtI3rxw0Ae1krJZnmIO3z_v-vXdlVnpIq0sk6Io8pb1moE/s200/device-2011-10-08-083106.png&quot; width=&quot;150&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr69qWH8O_OTa3JQa5tPhcQpu1Y9N9LSt1Nz5kRybfBeAFRLY5D0bnz8LnNj9UNmzxZKvSLa1z-bGr2gMFWN92jsF4fLJPVI5km7KrVDIuISAUoj3EB79-ucQ9C8ieuFp_9u4gzPuKCHc/s1600/device-2011-10-08-083118.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr69qWH8O_OTa3JQa5tPhcQpu1Y9N9LSt1Nz5kRybfBeAFRLY5D0bnz8LnNj9UNmzxZKvSLa1z-bGr2gMFWN92jsF4fLJPVI5km7KrVDIuISAUoj3EB79-ucQ9C8ieuFp_9u4gzPuKCHc/s200/device-2011-10-08-083118.png&quot; width=&quot;150&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPaCmVFF4c2vnzKpqnO0dyFZrROo8vVuV3_E5MhUB8SZuxqc8HPzU9EdG8m8DvsGYSIiTJ39KWE7Fi2sKoAfuGRocaFnn_nbGX9wcCjYgJYvoFn1FFs7UOH4-P7rGUsBwU0hgxM-Sx8DU/s1600/device-2011-10-08-083126.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPaCmVFF4c2vnzKpqnO0dyFZrROo8vVuV3_E5MhUB8SZuxqc8HPzU9EdG8m8DvsGYSIiTJ39KWE7Fi2sKoAfuGRocaFnn_nbGX9wcCjYgJYvoFn1FFs7UOH4-P7rGUsBwU0hgxM-Sx8DU/s200/device-2011-10-08-083126.png&quot; width=&quot;150&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
This can be down in two ways.&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
Option 01: changing the layout XML file to use the weight sum:&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;LinearLayout&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;android:orientation&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&quot;vertical&quot;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;android:id&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&quot;@+id/linearLayout1&quot;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;android:layout_height&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;fill_parent&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:layout_width&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;fill_parent&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;android:weightSum&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;3&quot;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:text&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;Button&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:id&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;@+id/button0&quot;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;fill_parent&quot;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_weight&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;android:layout_height&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;0dip&quot;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;span class=&quot;s2&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:text&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;Button&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:id&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;@+id/button1&quot;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;fill_parent&quot;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_weight&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:visibility&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;gone&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;android:layout_height&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;0dip&quot;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;s2&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:text&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;Button&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:id&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;@+id/button2&quot;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_weight&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;fill_parent&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;android:visibility&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;gone&quot;&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;android:layout_height&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;&quot;0dip&quot;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;span class=&quot;s2&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;i&gt;&lt;span class=&quot;s1&quot;&gt;LinearLayout&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;Option 02: using java code:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;@Override&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;public&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;void&lt;/span&gt;&lt;/span&gt;&amp;nbsp;onCheckedChanged(RadioGroup group,&amp;nbsp;&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt;&amp;nbsp;checkedId) {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;switch&lt;/span&gt;(group.getCheckedRadioButtonId()){&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;case&lt;/span&gt;&lt;/span&gt;&amp;nbsp;R.id.&lt;span class=&quot;s2&quot;&gt;radio0&lt;/span&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button0&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;VISIBLE&lt;/span&gt;);&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button1&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;INVISIBLE&lt;/span&gt;);&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button2&lt;/span&gt;.setVisibility(View.&lt;/b&gt;
&lt;b&gt;&lt;span class=&quot;s2&quot;&gt;INVISIBLE&lt;/span&gt;&lt;/b&gt;&lt;b&gt;);&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;case&lt;/span&gt;&lt;/span&gt;&amp;nbsp;R.id.&lt;span class=&quot;s2&quot;&gt;radio1&lt;/span&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button0&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;VISIBLE&lt;/span&gt;);&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button1&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;VISIBLE&lt;/span&gt;);&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button2&lt;/span&gt;.setVisibility(View.&lt;/b&gt;
&lt;b&gt;&lt;span class=&quot;s2&quot;&gt;INVISIBLE&lt;/span&gt;&lt;/b&gt;&lt;b&gt;);&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;case&lt;/span&gt;&lt;/span&gt;&amp;nbsp;R.id.&lt;span class=&quot;s2&quot;&gt;radio2&lt;/span&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button0&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;VISIBLE&lt;/span&gt;);&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button1&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;VISIBLE&lt;/span&gt;);&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; button2&lt;/span&gt;.setVisibility(View.&lt;span class=&quot;s2&quot;&gt;VISIBLE&lt;/span&gt;);&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
option 01 you should change the xml file and in option 02 you should change the java code.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/6578880688261297974/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/6578880688261297974' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/6578880688261297974'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/6578880688261297974'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2012/06/android-linearlayout-dynamically.html' title='Android: LinearLayout, Dynamically Arranging Views'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH5B1ou4CvgDIaVIK1X7uilNmGjsKFdZRgV4-vXvvPdccC0ZkHN7junZimoyRrvp-a7PzEav0AXOafnl2O3X12pjNHX-PzrZCoL2wasxb-vxkvwgRJsbCD1Dfe9nM8WvTtti5oL-RbWSg/s72-c/device-2011-10-07-220804.png" height="72" width="72"/><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-1423776222331983000</id><published>2012-05-19T21:15:00.000-07:00</published><updated>2012-05-20T18:55:27.242-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="Expand"/><category scheme="http://www.blogger.com/atom/ns#" term="Liner Layout"/><title type='text'>Android: Expand Liner Layout Beyond its Width</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In android, the layout weight parameter in the liner layout is very useful to layout views with relative ratios. Say you want to arrange two frames left and right, and right frame take&amp;nbsp;quoter&amp;nbsp;and right  take the balance.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEis4qkcYTdPiAY0VLn2FJEjtAXRfd-KqOnyXfPgQyHKYcLj0mRNiPrxb8BWJ0Z9ynMLjo4SPUcKkK3i1e8G7k8xX0wUmNCZWDZRiIbBcC3Q8rU7Z24WooYIRN8jVIXzbXjeMXBtHInCwdQ/s1600/device-2012-05-19-210856.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEis4qkcYTdPiAY0VLn2FJEjtAXRfd-KqOnyXfPgQyHKYcLj0mRNiPrxb8BWJ0Z9ynMLjo4SPUcKkK3i1e8G7k8xX0wUmNCZWDZRiIbBcC3Q8rU7Z24WooYIRN8jVIXzbXjeMXBtHInCwdQ/s200/device-2012-05-19-210856.png&quot; width=&quot;120&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
We can simply create this using following layout xml. Only thing is to noted down is, the width should be set to 0dip and weight to be set to 0.25 or 0.75 according to the requirement. That all.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;lt;?&lt;span class=&quot;s1&quot;&gt;xml&lt;/span&gt; version=&quot;1.0&quot; encoding=&quot;&lt;span class=&quot;s1&quot;&gt;utf&lt;/span&gt;-8&quot;?&amp;gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; android:layout_height=&quot;fill_parent&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; android:orientation=&quot;horizontal&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; android:weightSum=&quot;1&quot; &amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;FrameLayout&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;0dip&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;match_parent&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_weight=&quot;0.75&quot;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:background=&quot;#FF0000&quot; &amp;gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/FrameLayout&amp;gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;FrameLayout&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;match_parent&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_weight=&quot;0.25&quot;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:background=&quot;#00FF00&quot; &amp;gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;ToggleButton&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;wrap_content&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;wrap_content&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_gravity=&quot;center&quot; /&amp;gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/FrameLayout&amp;gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;lt;/LinearLayout&amp;gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
But in our case, we wanted to add another frame next to the right frame its width also 0.75 of the screen and in some user action, by moving the screen, the left frame should be hidden and 3rd frame should be shown.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiojkm63A2cl14nVT7WQLpTXf7XpOthhgcgDAflppfxUc6IwvLWXkFRiDGWGf0Qk1qtfvmMCNzpR3OMtv352OWCZLoZBdFi2jxHJuPONWlQ8Og-nG3Rlf0PtFM3MIUMiIzWFyoHqznFuSs/s1600/phone.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;105&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiojkm63A2cl14nVT7WQLpTXf7XpOthhgcgDAflppfxUc6IwvLWXkFRiDGWGf0Qk1qtfvmMCNzpR3OMtv352OWCZLoZBdFi2jxHJuPONWlQ8Og-nG3Rlf0PtFM3MIUMiIzWFyoHqznFuSs/s400/phone.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
So we created custom liner layout by extending the liner layout, where we override the on measure method to adjust its size by 0.75 of its size.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class ExpandedLinearLayout extends LinearLayout {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@SuppressWarnings(&quot;unused&quot;)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private static final String TAG = &quot;demo.beyond.layout.ExpandedLinearLayout&quot;;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public ExpandedLinearLayout(Context context) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;super(context);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public ExpandedLinearLayout(Context context, AttributeSet attrs) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;super(context, attrs);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public ExpandedLinearLayout(Context context, AttributeSet attrs, int defStyle) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;super(context, attrs, defStyle);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;super.onMeasure(widthMeasureSpec, heightMeasureSpec);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;b&gt;setMeasuredDimension((int) (1.75f*getMeasuredWidth()), getMeasuredHeight());&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
And add another new frame to above layout with weight 0.75. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;lt;?&lt;span class=&quot;s1&quot;&gt;xml&lt;/span&gt; version=&quot;1.0&quot; encoding=&quot;&lt;span class=&quot;s1&quot;&gt;utf&lt;/span&gt;-8&quot;?&amp;gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;................. &amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;FrameLayout&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;0dip&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;match_parent&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_weight=&quot;0.75&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:background=&quot;#0000FF&quot; &amp;gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/FrameLayout&amp;gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;lt;/LinearLayout&amp;gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we add the animation for the on click.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class DemoExpandLayoutActivity extends Activity implements OnClickListener {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; private LinearLayout mLinearLayout;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private FrameLayout mFrameLayout1;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private ToggleButton mToggleButton;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/** Called when the activity is first created. */&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @Override&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super.onCreate(savedInstanceState);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setContentView(R.layout.main);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mLinearLayout = (LinearLayout)findViewById(R.id.frame);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mFrameLayout1 = (FrameLayout)findViewById(R.id.frameLayout1);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mToggleButton = (ToggleButton)findViewById(R.id.toggleButton1);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mToggleButton.setOnClickListener(this);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Override&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public void onClick(View arg0) {&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;float factor = 1.0f*mFrameLayout1.getWidth()/mLinearLayout.getWidth();&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(mToggleButton.isChecked()){&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;mLinearLayout.setTranslationX(-mFrameLayout1.getWidth());&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;TranslateAnimation translateAnimation = new TranslateAnimation(&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;TranslateAnimation.RELATIVE_TO_PARENT,&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;factor,&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;TranslateAnimation.RELATIVE_TO_PARENT,&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;0.0f,&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;TranslateAnimation.RELATIVE_TO_PARENT,&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;0.0f,&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;TranslateAnimation.RELATIVE_TO_PARENT,&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;0.0f);&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;translateAnimation.setDuration(1000);&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;LayoutAnimationController layoutAnimationController = new LayoutAnimationController(translateAnimation,0.1f);&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;mLinearLayout.setLayoutAnimation(layoutAnimationController);&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}else{&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;mLinearLayout.setTranslationX(0);&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;TranslateAnimation translateAnimation = new TranslateAnimation(&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;TranslateAnimation.RELATIVE_TO_PARENT,&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;-factor,&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;TranslateAnimation.RELATIVE_TO_PARENT,&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;0.0f,&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;TranslateAnimation.RELATIVE_TO_PARENT,&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;0.0f,&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;TranslateAnimation.RELATIVE_TO_PARENT,&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;0.0f);&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;translateAnimation.setDuration(1000);&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;LayoutAnimationController layoutAnimationController = new LayoutAnimationController(translateAnimation,-0.1f);&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;mLinearLayout.setLayoutAnimation(layoutAnimationController);&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;}&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
But that didn&#39;t quit worked out, because liner layout ignores views If those out side the weight sum.&lt;br /&gt;
&lt;br /&gt;
But if we add views as match patent, with layout weights, liner layout behaves differently. It draws all the views beyond its boundary.&lt;br /&gt;
In this case the actual width of each view was not proportional to layout weight what we set in layout XML.&lt;br /&gt;
So to find out the relation, I just try for different values and  plot the following graph and got the below equation. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSgGyVODeUhKZKo2CLIApcF7fxYCGEzOcklqlJ4yTPVXgGmz5wI7hYVCYyZyzF2UOdLvYJerUYw8yeqJQd7zbSbr-5jAzTgzFFqTF0e7zBohX5QcIcEpVEtiIhRhzA7WlTB4mClKjyAOg/s1600/chart_1+(1).png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;246&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSgGyVODeUhKZKo2CLIApcF7fxYCGEzOcklqlJ4yTPVXgGmz5wI7hYVCYyZyzF2UOdLvYJerUYw8yeqJQd7zbSbr-5jAzTgzFFqTF0e7zBohX5QcIcEpVEtiIhRhzA7WlTB4mClKjyAOg/s400/chart_1+(1).png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
I couldn&#39;t find any direct evidence in android code base or may have to check some more android source code.&amp;nbsp;But this is good enough to calculate the proper values for us.&lt;br /&gt;
&lt;br /&gt;
Then I changed the layout XML with those values.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;lt;?&lt;span class=&quot;s1&quot;&gt;xml&lt;/span&gt; version=&quot;1.0&quot; encoding=&quot;&lt;span class=&quot;s1&quot;&gt;utf&lt;/span&gt;-8&quot;?&amp;gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;lt;demo.beyond.layout.ExpandedLinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; android:id=&quot;@+id/frame&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; android:layout_height=&quot;fill_parent&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; android:orientation=&quot;horizontal&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; android:weightSum=&quot;1&quot; &amp;gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;FrameLayout&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/frameLayout1&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;match_parent&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_weight=&quot;0.125&quot;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:background=&quot;#FF0000&quot; &amp;gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/FrameLayout&amp;gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;FrameLayout&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/frameLayout2&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;match_parent&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_weight=&quot;0.375&quot;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:background=&quot;#00FF00&quot; &amp;gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;ToggleButton&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/toggleButton1&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;wrap_content&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;wrap_content&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_gravity=&quot;center&quot; /&amp;gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/FrameLayout&amp;gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;FrameLayout&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/frameLayout3&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;match_parent&quot;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_weight=&quot;0.125&quot;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:background=&quot;#0000FF&quot; &amp;gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/FrameLayout&amp;gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;lt;/demo.beyond.layout.ExpandedLinearLayout&amp;gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Further more I modified the expanded liner layout with this formula, so that it can use in all cases.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
@Override&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;super.onMeasure(widthMeasureSpec, heightMeasureSpec);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int numberOfChild = getChildCount();&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;float totalWidth = 0;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;for(int i = 0;i &amp;lt; numberOfChild;i++){&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;totalWidth+=getMeasuredWidth()&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;*(1 - 2*((LinearLayout.LayoutParams)getChildAt(i).getLayoutParams()).weight);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;setMeasuredDimension((int) totalWidth, getMeasuredHeight());&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
}&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
Source Code :&amp;nbsp;&lt;a href=&quot;http://dl.dropbox.com/u/7717254/DemoExpandLayout.zip&quot;&gt;http://dl.dropbox.com/u/7717254/DemoExpandLayout.zip&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
Here I have uploaded the source code, try it your self and let me know your feedback or let me know if you have any other option.&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/1423776222331983000/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/1423776222331983000' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/1423776222331983000'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/1423776222331983000'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2012/05/android-expand-liner-layout-beyond-its.html' title='Android: Expand Liner Layout Beyond its Width'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEis4qkcYTdPiAY0VLn2FJEjtAXRfd-KqOnyXfPgQyHKYcLj0mRNiPrxb8BWJ0Z9ynMLjo4SPUcKkK3i1e8G7k8xX0wUmNCZWDZRiIbBcC3Q8rU7Z24WooYIRN8jVIXzbXjeMXBtHInCwdQ/s72-c/device-2012-05-19-210856.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-4116363667117788550</id><published>2012-05-15T23:39:00.001-07:00</published><updated>2012-05-15T23:39:42.298-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="media scanner"/><title type='text'>Android: How to Check if Media Scanner is Running?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In our application, some of the action need to be&amp;nbsp;blocked while android media scanner running (For example loading existing media and listing down).&lt;br /&gt;
&lt;br /&gt;
In this case, we couldn&#39;t find a&amp;nbsp;direct&amp;nbsp;API to check if Media Scanner is running. We could find following two options:&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Option 01:&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
Android will broadcast&amp;nbsp;&lt;b&gt;Intent.ACTION_MEDIA_SCANNER_STARTED&lt;/b&gt;,&amp;nbsp;&lt;b&gt;Intent.ACTION_MEDIA_SCANNER_FINISHED&lt;/b&gt; in starting and finishing of scanning&amp;nbsp;respectively. So we create following &amp;nbsp;BroadcastReceiver:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;public class&lt;/span&gt; MediaScannerBroadcastReceiver &lt;span style=&quot;color: #a64d79;&quot;&gt;extends&lt;/span&gt; BroadcastReceiver {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;public static&lt;/span&gt; boolean mMedaiScanning = &lt;span style=&quot;color: #a64d79;&quot;&gt;false&lt;/span&gt;;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @Override&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;public void&lt;/span&gt; onReceive(Context context, Intent intent) {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;if(intent.getAction().equals(Intent.&lt;span style=&quot;color: #3d85c6;&quot;&gt;ACTION_MEDIA_SCANNER_STARTED&lt;/span&gt;)){&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;mMedaiScanning = &lt;span style=&quot;color: #a64d79;&quot;&gt;true&lt;/span&gt;;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;if(intent.getAction().equals(Intent.&lt;span style=&quot;color: #3d85c6;&quot;&gt;ACTION_MEDIA_SCANNER_FINISHED&lt;/span&gt;)){&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;mMedaiScanning = &lt;span style=&quot;color: #a64d79;&quot;&gt;false&lt;/span&gt;;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And register this in manifest file:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;receiver&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #a64d79;&quot;&gt;android:name&lt;/span&gt;=&quot;&amp;nbsp;&lt;span style=&quot;color: #3d85c6;&quot;&gt;MediaScannerBroadcastReceiver&lt;/span&gt;&quot;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #45818e;&quot;&gt;intent-filter&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;
&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #45818e;&quot;&gt;action&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #a64d79;&quot;&gt;android:name&lt;/span&gt;=&quot;&lt;span style=&quot;color: #3d85c6;&quot;&gt;android.intent.action.MEDIA_SCANNER_FINISHED&lt;/span&gt;&quot;
&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #45818e;&quot;&gt;/action&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #45818e;&quot;&gt;action&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #a64d79;&quot;&gt;android:name&lt;/span&gt;=&quot;&lt;span style=&quot;color: #3d85c6;&quot;&gt;android.intent.action.MEDIA_SCANNER_STARTED&lt;/span&gt;&quot;
&lt;span style=&quot;color: #45818e;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #45818e;&quot;&gt;/action&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;
&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #45818e;&quot;&gt;data&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #a64d79;&quot;&gt;android:scheme&lt;/span&gt;=&quot;&lt;span style=&quot;color: #3d85c6;&quot;&gt;file&lt;/span&gt;&quot;
&lt;span style=&quot;color: #45818e;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&amp;gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #45818e;&quot;&gt;/data&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;
&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #45818e;&quot;&gt;/intent-filter&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;/receiver&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;color: #45818e;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;&lt;br /&gt;
Then in cases we we wanted to check the condition we sued as following:&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;if&lt;/span&gt;(
MediaScannerBroadcastReceiver.mMedaiScanning){&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;.....&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
But, most of the devices will run Media Scanner in boot up, in adding SDCard or mount/unmount devices to PC. In those cases our application is&amp;nbsp;invoked and loaded into memory.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Option 02:&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
found that the media scanner service insert and delete a record into media store when starting and finishing the scanning. So we try to check the record in the media store as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: white; font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;&quot;&gt;
&lt;i&gt;&lt;span style=&quot;color: #993399;&quot;&gt;private boolean&amp;nbsp;&lt;/span&gt;isMediaScannerRunning() {&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;&quot;&gt;
&lt;i&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;	&lt;/span&gt;Cursor query = getContentResolver().query(&lt;wbr&gt;&lt;/wbr&gt;MediaStore.getMediaScannerUri(&lt;wbr&gt;&lt;/wbr&gt;),&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;&quot;&gt;
&lt;i&gt;&lt;span style=&quot;color: #993399;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;new&lt;/span&gt;&amp;nbsp;String[]{MediaStore.&lt;span style=&quot;color: #3333ff;&quot;&gt;MEDIA_&lt;wbr&gt;&lt;/wbr&gt;SCANNER_VOLUME&lt;/span&gt;},&amp;nbsp;&lt;span style=&quot;color: #993399;&quot;&gt;null&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: #993399;&quot;&gt;null&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: #993399;&quot;&gt;null&lt;/span&gt;);&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;&quot;&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #993399;&quot;&gt;if&lt;/span&gt;(query!=null){&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;&quot;&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #993399;&quot;&gt;if&lt;/span&gt;(query.moveToFirst()){&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;&quot;&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;		&lt;/span&gt;int columnIndex = query.getColumnIndex(&lt;wbr&gt;&lt;/wbr&gt;MediaStore.&lt;span style=&quot;color: #3333ff;&quot;&gt;MEDIA_SCANNER_&lt;wbr&gt;&lt;/wbr&gt;VOLUME&lt;/span&gt;);&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;&quot;&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;		&lt;/span&gt;String volumeName = query.getString(columnIndex);&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;&quot;&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #993399;&quot;&gt;if&lt;/span&gt;(volumeName!=&lt;span style=&quot;color: #993399;&quot;&gt;null&lt;/span&gt;){&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;&quot;&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #993399;&quot;&gt;return true&lt;/span&gt;;&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;&quot;&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;		&lt;/span&gt;}&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;&quot;&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;	&lt;/span&gt;}&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;&quot;&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;	&lt;/span&gt;query.close();&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;&quot;&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;&quot;&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #993399;&quot;&gt;return false&lt;/span&gt;;&lt;/i&gt;&lt;/div&gt;
&lt;i style=&quot;font-family: arial, sans-serif; font-size: 13px; text-align: -webkit-auto;&quot;&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
This option will not load the application while media scanner running. But need to&amp;nbsp;consider&amp;nbsp;its costly operation in query.&lt;br /&gt;
&lt;br /&gt;
Lets check both options for its pros and cons.&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/4116363667117788550/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/4116363667117788550' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/4116363667117788550'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/4116363667117788550'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2012/05/android-how-to-check-if-media-scanner.html' title='Android: How to Check if Media Scanner is Running?'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-3942721232782450137</id><published>2011-10-01T21:46:00.000-07:00</published><updated>2011-10-01T21:46:17.752-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="project preparation"/><title type='text'>Part 7: Thoughts of “How we do?” - Reading from Near vs Far</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4PThA6jbXWOnX9WqUGoorjl_5cIYQ3ZMnAj2BajjlEX3SNy9unxV_uXd9X7JKgEUmgrlnRtJofjxXXcsX3YcUhQfXZukX4xPLQ4jBiZaMCeRsH-pxN20JrZX-Orz5U1d1ER7MVY9FGF8/s1600/bus+%25281%2529.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;208&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4PThA6jbXWOnX9WqUGoorjl_5cIYQ3ZMnAj2BajjlEX3SNy9unxV_uXd9X7JKgEUmgrlnRtJofjxXXcsX3YcUhQfXZukX4xPLQ4jBiZaMCeRsH-pxN20JrZX-Orz5U1d1ER7MVY9FGF8/s320/bus+%25281%2529.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Say you are traveling in a bus and trying to read a board on both sides of the road. First board is on the same side where you are traveling and the second board on the other side of the road. Both has same text. And the board on the opposite side has enough font size to read it from the bus which you are traveling.&amp;nbsp;Normally we can only star reading once we come inside the visual angle of the board.&lt;br /&gt;
&lt;br /&gt;
Assume you are reading both boards in two different situation from start to end while bus moving in same speed. You will understand that, you can read more from the board which is in the opposite side.&amp;nbsp;So when we are traveling, without reducing our speed, we can&#39;t read more from near, rather from far we can. But the distance should be enough to identify the letters, that all.&lt;br /&gt;
&lt;br /&gt;
Now, let see how we can apply this into a real life situations.&lt;br /&gt;
&lt;br /&gt;
Team leaders, if your team members are currently working in a project with a constant speed. And you are hearing some new project opportunity. It is not good to wait until your project got confirm and then bring it to the members to their close attention. Because members have to slowdown their current project in order to prepare the new project. Instead of that, if you let them prepare the new project early as possible in a relax mode, &amp;nbsp;this will not much affect the current project speed.&lt;br /&gt;
&lt;br /&gt;
Here one of the different between close attention and relax mode would be, in close attention team leader will expect and check for updates very frequently, rather in relax mode leader could wait until the team member bring  updates to leaders&#39; table or expect and check update&amp;nbsp;occasionally.&lt;br /&gt;
&lt;br /&gt;
One concern may be: change in the project detail will make the preparation waste, but that is not fully true. Because if we have already prepared and then you summaries the different from early draft we don&#39;t need much effect to override the new changes. If the project details totally change, then of cause all the initial preparation is waste. Mostly that not the case.&lt;br /&gt;
&lt;br /&gt;
But for the success of relax mode approach, team member should have enough skill level. They should be proactive to prepare project in early stage,  self motivated to prepare project and provide updates. They should be able manage and balance work load in preparation new project with the current project. &lt;br /&gt;
&lt;br /&gt;
Feather more, letting the team member to prepare the project early will lead to understand any unclear or impossible areas in the project so that the project could be modify accordingly. This will help in project&amp;nbsp;executions very much.&lt;br /&gt;
&lt;br /&gt;
So, I feel it is better to do go for a early preparation of new project. Both team leaders and members should understand the pros and cons in this&amp;nbsp;approach and should act&amp;nbsp;accordingly. This will bring a best team and best product in the end.&lt;br /&gt;
&lt;br /&gt;
Let me find out another real example as above and meet you another post. Bye&amp;nbsp;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/3942721232782450137/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/3942721232782450137' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/3942721232782450137'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/3942721232782450137'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2011/10/part-7-thoughts-of-how-we-do-reading.html' title='Part 7: Thoughts of “How we do?” - Reading from Near vs Far'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4PThA6jbXWOnX9WqUGoorjl_5cIYQ3ZMnAj2BajjlEX3SNy9unxV_uXd9X7JKgEUmgrlnRtJofjxXXcsX3YcUhQfXZukX4xPLQ4jBiZaMCeRsH-pxN20JrZX-Orz5U1d1ER7MVY9FGF8/s72-c/bus+%25281%2529.jpg" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-5189205447276121319</id><published>2011-10-01T09:38:00.000-07:00</published><updated>2011-10-01T09:44:07.028-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="custom view"/><category scheme="http://www.blogger.com/atom/ns#" term="r theta"/><title type='text'>Android : Drawing View with shapes plotted in r theta (r,θ) relation</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjm1IjpNRXZlvTddX6jvUQ8pQqvotcLBt1DHae7cN5BF4yJ_aelQ9Vu52kzyaINesylPA9fo-m3IIbA17edDNNz8E7xQY91i496cUjDSidV-oLYE9XM-qrpRyRtkiSb80Nfl1pNL2ROr3E/s1600/device-2011-09-30-233459.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjm1IjpNRXZlvTddX6jvUQ8pQqvotcLBt1DHae7cN5BF4yJ_aelQ9Vu52kzyaINesylPA9fo-m3IIbA17edDNNz8E7xQY91i496cUjDSidV-oLYE9XM-qrpRyRtkiSb80Nfl1pNL2ROr3E/s200/device-2011-09-30-233459.png&quot; width=&quot;150&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;r = 0.875*width/2+0.125cos(12θ)&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2oyjYxEDVRxobbrKr9wKeEJ9vYvlZEr_pKU-Ff5Ui9YsGqRV3t7qzEe4H7Ba1sJi23JT5-4lq7O7TWEstl6b4FIqEmAl_5dcUqTUxmn3ORBp7s-ObqmDhjCstf1X6csPj3AdgLvPum9Y/s1600/device-2011-09-30-234054.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2oyjYxEDVRxobbrKr9wKeEJ9vYvlZEr_pKU-Ff5Ui9YsGqRV3t7qzEe4H7Ba1sJi23JT5-4lq7O7TWEstl6b4FIqEmAl_5dcUqTUxmn3ORBp7s-ObqmDhjCstf1X6csPj3AdgLvPum9Y/s200/device-2011-09-30-234054.png&quot; width=&quot;150&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;r - width/2*cos(4θ)&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmP5hxW2_4-OvMIU_Eg-r_rpXSPZ-aHTS40hf6t9A2OWpFtYz7exvkqavOb0-ZKbxuyVuru6Y0h6lkBEaDS8WinvUAy94iCTKhiI-oXfH76gqGVyvRamTgiPopu4gDkLaMsbdpsvYrWPs/s1600/device-2011-09-30-222359.png&quot; imageanchor=&quot;1&quot; style=&quot;display: inline !important; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmP5hxW2_4-OvMIU_Eg-r_rpXSPZ-aHTS40hf6t9A2OWpFtYz7exvkqavOb0-ZKbxuyVuru6Y0h6lkBEaDS8WinvUAy94iCTKhiI-oXfH76gqGVyvRamTgiPopu4gDkLaMsbdpsvYrWPs/s200/device-2011-09-30-222359.png&quot; width=&quot;150&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;r - width/2&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
Say you want to create views which contains shares as shown above. In those each circle drawn in (r,&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;θ&lt;/span&gt;)&amp;nbsp;relation. I implemented following onDraw method with possible two options.&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Option 1&lt;/b&gt;.&amp;nbsp;Rotating&amp;nbsp;canvas and drawing circles - this is&amp;nbsp;direct use of (r ,&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;θ)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Option 2&lt;/b&gt;. Converting points into x,y plan&amp;nbsp;coordinate and drawing the circle.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cccccc;&quot;&gt;@Override&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;void&lt;/span&gt; onDraw(Canvas canvas) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt; width = getWidth()/2;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt; height = getHeight()/2;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;Paint paint = new Paint();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;paint.setColor(Color.RED);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;&lt;b&gt; //Option 1&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;long time = System.currentTimeMillis();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.save();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.translate(width, height);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;for&lt;/span&gt;(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;int&lt;/span&gt; i = 0 ; i &amp;lt; 13;i++){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;canvas.drawCircle(width, 0, width*0.2f, paint);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;canvas.rotate(-15);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.restore();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;Log.i(TAG, &quot;::onDraw:&quot; + &quot;time 1 = &quot; + (System.currentTimeMillis()-time));&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;//Option 2&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;long&lt;/span&gt; time1 = System.currentTimeMillis();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.save();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.translate(width, height);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt; angle = 0;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;for&lt;/span&gt;(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;int&lt;/span&gt; i = 0 ; i &amp;lt; 13;i++){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt; radian = (&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt;) (Math.PI*angle/180.0f);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;canvas.drawCircle((&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt;) (width*Math.cos(radian)),&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt;) (width*Math.sin(radian)), width*0.2f, paint);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;angle+=15;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.restore();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;Log.i(TAG, &quot;::onDraw:&quot; + &quot;time 2 = &quot; + (System.currentTimeMillis()-time1));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Since above coding draw only 13 circles, I couldn&#39;t find a clear different in&amp;nbsp;execution&amp;nbsp;time for both options. So I change the code to draw 180 circle as follows:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR2WQutQxuttk3QleGDxlMAo8Ct0_0E33VbRGBXfUAfGTTEf_hcA3lpKBYyq9NOhR8vo_OLiXD2zdxCe9loHsORsiZGUOlVoB7dUsMBrviwo9n00GsBaHw3ipRliAO65__1ZZ5SDuiZF8/s1600/device-2011-10-01-232956.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR2WQutQxuttk3QleGDxlMAo8Ct0_0E33VbRGBXfUAfGTTEf_hcA3lpKBYyq9NOhR8vo_OLiXD2zdxCe9loHsORsiZGUOlVoB7dUsMBrviwo9n00GsBaHw3ipRliAO65__1ZZ5SDuiZF8/s200/device-2011-10-01-232956.png&quot; width=&quot;150&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cccccc;&quot;&gt;@Override&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;void&lt;/span&gt; onDraw(Canvas canvas) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt; width = getWidth()/2;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt; height = getHeight()/2;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;Paint paint = new Paint();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;paint.setColor(Color.RED);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;long&lt;/span&gt; time1 = System.currentTimeMillis();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.save();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.translate(width, height);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;for&lt;/span&gt;(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;int&lt;/span&gt; i = 0 ; i &amp;lt; 180;i++){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt; radius = width;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;canvas.drawCircle(radius, 0, 2.0f, paint);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;canvas.rotate(-1);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.restore();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;time1 = System.currentTimeMillis()-time1;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;long&lt;/span&gt; time2 = System.currentTimeMillis();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.save();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.translate(width, height);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;for&lt;/span&gt;(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;int&lt;/span&gt; i = 0 ; i &amp;lt; 180;i++){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt; radian = (&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt;) (Math.PI*i/180.0f);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;float radius = width;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;canvas.drawCircle((&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt;) (radius*Math.cos(radian)),&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt;) (radius*Math.sin(radian)), 2.0f, paint);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.restore();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;time2 = System.currentTimeMillis()-time2;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;Log.i(TAG, &quot;::onDraw:&quot; + &quot;time1,time2, (time1-time2) = &quot;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;+ time1 + &quot;,&quot;+time2+&quot;,&quot;+(time1-time2));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Now i could see clear different and &lt;b&gt;Option 2&lt;/b&gt; is faster than &lt;b&gt;Option 1&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;INFO/demo.theta.DemoRTheta(5302): ::onDraw:time1,time2, (time1-time2) = 62,35,27&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;INFO/demo.theta.DemoRTheta(5302): ::onDraw:time1,time2, (time1-time2) = 66,36,30&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;INFO/demo.theta.DemoRTheta(5302): ::onDraw:time1,time2, (time1-time2) = 66,37,29&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;INFO/demo.theta.DemoRTheta(5302): ::onDraw:time1,time2, (time1-time2) = 63,35,28&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;INFO/demo.theta.DemoRTheta(5302): ::onDraw:time1,time2, (time1-time2) = 68,34,34&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;INFO/demo.theta.DemoRTheta(5302): ::onDraw:time1,time2, (time1-time2) = 63,35,28&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;INFO/demo.theta.DemoRTheta(5302): ::onDraw:time1,time2, (time1-time2) = 61,35,26&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;INFO/demo.theta.DemoRTheta(5302): ::onDraw:time1,time2, (time1-time2) = 59,35,24&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;INFO/demo.theta.DemoRTheta(5302): ::onDraw:time1,time2, (time1-time2) = 68,40,28&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;INFO/demo.theta.DemoRTheta(5302): ::onDraw:time1,time2, (time1-time2) = 75,32,43&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;INFO/demo.theta.DemoRTheta(5302): ::onDraw:time1,time2, (time1-time2) = 65,32,33&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;INFO/demo.theta.DemoRTheta(5302): ::onDraw:time1,time2, (time1-time2) = 52,36,16&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
Here you have expresions for other above graphs.&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;radian&lt;/span&gt; = (&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt;) (Math.PI*i/180.0f);&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;	&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt;&lt;/span&gt; radius = width;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt; radius = (&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt;) (width*Math.cos(4*&lt;span class=&quot;s1&quot;&gt;radian&lt;/span&gt;));&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt; radius = (&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;float&lt;/span&gt;) (0.875f*width+0.125f*width*Math.cos(12*&lt;span class=&quot;s1&quot;&gt;radian&lt;/span&gt;));&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
But Option 2 needs some extra&amp;nbsp;calculation to translate&amp;nbsp;&amp;nbsp;(r ,&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot;&gt;θ) into (x, y), in above examples we needed to determine only center of the circle.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;Let see some of the view as follows.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCcF7oMsDx83krESqrnzheu4HewZpF35mHcvafeKaOiBeIWvb1x6cWwl1yV2Lqe8UsoJDFV7zuXP3__uyQlNQgapjMoisk3TnSMeovkLEe9olyaelBQbfTPR_hDh3yvZp5As-lifyYNr8/s1600/device-2011-10-02-000458.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCcF7oMsDx83krESqrnzheu4HewZpF35mHcvafeKaOiBeIWvb1x6cWwl1yV2Lqe8UsoJDFV7zuXP3__uyQlNQgapjMoisk3TnSMeovkLEe9olyaelBQbfTPR_hDh3yvZp5As-lifyYNr8/s200/device-2011-10-02-000458.png&quot; width=&quot;150&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;&lt;i&gt;canvas.save();&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;canvas.translate(width, height);&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;for(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;int&lt;/span&gt; i = 0 ; i &amp;lt; 72;i++){&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.drawLine(width*0.8F, 0, width*1.0f, 0, paint);&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.rotate(5);&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;}&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;canvas.restore();&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Now we have to find start x,y and end x,y that need extra calculation and extra&amp;nbsp;analysis effect to come up with that expresion.&lt;br /&gt;
Next one is more&amp;nbsp;interesting need to use Path.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHYjsqqhAUSHv9RoNngOxMcjXaorE7_kHKqE4S8TOs9-3Jw8r621lRbDHn545ACvu-juw6kY5s3siH4VPhMxmMqJATGfOo_h_URZM6guq2ksUlgWn7p9amPMWsPuppWzqCO88of4zUIso/s1600/device-2011-10-02-001912.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHYjsqqhAUSHv9RoNngOxMcjXaorE7_kHKqE4S8TOs9-3Jw8r621lRbDHn545ACvu-juw6kY5s3siH4VPhMxmMqJATGfOo_h_URZM6guq2ksUlgWn7p9amPMWsPuppWzqCO88of4zUIso/s200/device-2011-10-02-001912.png&quot; width=&quot;150&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;canvas.save();&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;canvas.translate(width, height);&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;for&lt;/span&gt;(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;int&lt;/span&gt; i = 0 ; i &amp;lt; 18;i++){&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;Path path = new Path();&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;path.moveTo(width*0.8F, 0);&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;path.lineTo(width, width*0.1F);&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;path.lineTo(width, -width*0.1F);&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;path.lineTo(width*0.8F, 0);&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.drawPath(path, paint);&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;canvas.rotate(20);&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;}&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;canvas.restore();&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Now you can find translation expression and can find out which one is faster in each cases.&lt;br /&gt;
Enjoy!&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/5189205447276121319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/5189205447276121319' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/5189205447276121319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/5189205447276121319'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2011/10/android-drawing-view-with-shapes.html' title='Android : Drawing View with shapes plotted in r theta (r,θ) relation'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjm1IjpNRXZlvTddX6jvUQ8pQqvotcLBt1DHae7cN5BF4yJ_aelQ9Vu52kzyaINesylPA9fo-m3IIbA17edDNNz8E7xQY91i496cUjDSidV-oLYE9XM-qrpRyRtkiSb80Nfl1pNL2ROr3E/s72-c/device-2011-09-30-233459.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-1047712324500330091</id><published>2011-09-27T08:45:00.000-07:00</published><updated>2011-09-27T08:45:25.203-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Adaptor"/><category scheme="http://www.blogger.com/atom/ns#" term="Grid"/><category scheme="http://www.blogger.com/atom/ns#" term="left to right"/><category scheme="http://www.blogger.com/atom/ns#" term="top to bottom"/><title type='text'>Grid, Adaptor, left to right into top to bottom</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Say we have list of object as follows,&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
list =&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUgTLsY3vORGoFSEBuw-v1LBGn7fPBs2SwLSzcNYlXujgxhmBg4EUk9aXm50H5SnHYcYVMvSLfd9UoM-eRhGy9U97K5TSFuX5DZbGn_d8Q5MtMRYaDBsI56u0QKX09NApjDfiqdQXm30U/s1600/list.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;21&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUgTLsY3vORGoFSEBuw-v1LBGn7fPBs2SwLSzcNYlXujgxhmBg4EUk9aXm50H5SnHYcYVMvSLfd9UoM-eRhGy9U97K5TSFuX5DZbGn_d8Q5MtMRYaDBsI56u0QKX09NApjDfiqdQXm30U/s320/list.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
.size() = 14&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
and need to show it in grid control that scroll vertically as follows,&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5cBHZuoDLNyvZ7ijD18bv7rkJbxgcHMcdnFJUqeG19htlI7af-NhGJyySw-yTdrIbhaiK33cZNA6qX29GGXs0F7T5Xnw_mZHAFHjxurIjtjQUU1_MFQdO9werdS4_bNxUd8sURAX90Fk/s1600/gridv.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5cBHZuoDLNyvZ7ijD18bv7rkJbxgcHMcdnFJUqeG19htlI7af-NhGJyySw-yTdrIbhaiK33cZNA6qX29GGXs0F7T5Xnw_mZHAFHjxurIjtjQUU1_MFQdO9werdS4_bNxUd8sURAX90Fk/s1600/gridv.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;// assume we want three columns.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;int&lt;/span&gt; columns = 3;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;// first calculate number of rows.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;int&lt;/span&gt; rows = (columns-1+list.size())/columns;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Or into grid control that scroll&amp;nbsp;horizontally as follows,&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMigqsFg2YNpR7IFp7wcTXPDFhLtlpyB0I7vVhb6aIhtBtbrqXErKQE6HOt3x54U30SxXNJLNXMD-yvLd0z_F6GStNigeR-BOPmvjkYqYGKyNXfsc0tG2SVfUa8g1yHuyK77Oxe-4hbY0/s1600/gridh.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;140&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMigqsFg2YNpR7IFp7wcTXPDFhLtlpyB0I7vVhb6aIhtBtbrqXErKQE6HOt3x54U30SxXNJLNXMD-yvLd0z_F6GStNigeR-BOPmvjkYqYGKyNXfsc0tG2SVfUa8g1yHuyK77Oxe-4hbY0/s320/gridh.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;//assume we want three rows.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;int&lt;/span&gt; rows = 3;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;// first calculate number of rows.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;int&lt;/span&gt; columns = (rows-1+list.size())/rows;&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
Mostly we use adaptor to fetch the item to show in each cell.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0-rIgwLS9dqEHI8LsDVf_ilmisc3aW76KptrMqijG1mFPcLrwNCMFLJ8_ErjnewOeHF4UzOOJ7D1djKx2H590BCXVv9QbOUjbGEpeBs0g8utzuQPE1bISzZEwpUWHI7G9NUzmEA_z654/s1600/grida.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;126&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0-rIgwLS9dqEHI8LsDVf_ilmisc3aW76KptrMqijG1mFPcLrwNCMFLJ8_ErjnewOeHF4UzOOJ7D1djKx2H590BCXVv9QbOUjbGEpeBs0g8utzuQPE1bISzZEwpUWHI7G9NUzmEA_z654/s320/grida.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
In this case adaptor can choose the index equal to position,&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;int&lt;/span&gt; index = position;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;return&lt;/span&gt; list.get(index);&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
But say some cases we may have to change to order in display. for&amp;nbsp;example. top to bottom as shown below:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeLeZVRNMGL2oVLSRNYBVdzLu75q7Qb8w5FmQzb4pjYZxJoS_w-a1joH8Bn1D_0J9uxzRiL6_3otk6fAVm9ffdzHn4XDj2lGxIuKKvBQiqYiz4uhZcLcXSPUzLNBTa2TfPFgRGmWc1GRg/s1600/gridhi.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;140&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeLeZVRNMGL2oVLSRNYBVdzLu75q7Qb8w5FmQzb4pjYZxJoS_w-a1joH8Bn1D_0J9uxzRiL6_3otk6fAVm9ffdzHn4XDj2lGxIuKKvBQiqYiz4uhZcLcXSPUzLNBTa2TfPFgRGmWc1GRg/s320/gridhi.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
But if the control fetch base on position from left to right as show below:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsOYVYYFQ_kOsuQ4NKV3u7gr2E1BJ7FbjnAhtenv_0p1ZsvzqI-A6inPiUSaE2M-TXpYPo9rYZJmZk9Jjl_C37ho0RFrlAhsiunA01oWk7nwO1A3PsnLgUWA9YdKH7v4GjOy5ks2k9m_k/s1600/gridhp.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;140&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsOYVYYFQ_kOsuQ4NKV3u7gr2E1BJ7FbjnAhtenv_0p1ZsvzqI-A6inPiUSaE2M-TXpYPo9rYZJmZk9Jjl_C37ho0RFrlAhsiunA01oWk7nwO1A3PsnLgUWA9YdKH7v4GjOy5ks2k9m_k/s320/gridhp.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
then, we need to add proper calculation inside the adaptor:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;int&lt;/span&gt; index =position/columns+position%columns*rows;&lt;/b&gt;&lt;br /&gt;








&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;return&lt;/span&gt;&amp;nbsp;list.get(index);&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/1047712324500330091/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/1047712324500330091' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/1047712324500330091'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/1047712324500330091'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2011/09/grid-adaptor-left-to-right-into-top-to.html' title='Grid, Adaptor, left to right into top to bottom'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUgTLsY3vORGoFSEBuw-v1LBGn7fPBs2SwLSzcNYlXujgxhmBg4EUk9aXm50H5SnHYcYVMvSLfd9UoM-eRhGy9U97K5TSFuX5DZbGn_d8Q5MtMRYaDBsI56u0QKX09NApjDfiqdQXm30U/s72-c/list.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9106967537835418775.post-6249659917056274312</id><published>2011-09-15T06:11:00.000-07:00</published><updated>2011-09-15T06:15:39.124-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="alignment"/><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="base line"/><category scheme="http://www.blogger.com/atom/ns#" term="custom view"/><title type='text'>Android: Aligning Custom Views at Base Line</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Have you ever try to align a non-symmetric custom view at a custom base line as follows?&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0qUB0fJVaIF_0bJ5L_AKS-st5pk9VjaiGXyfQ3nd6YrR2_X4r1vgHtMNFf1Lvz9F_R6S-64Nm_63-PitYBNrzVwfaR0bqpTfhBjs0EndSr9jOvBzPVAOB5xHTkRXQgjCkhHJY4ii49Pk/s1600/%2560Screenshot.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0qUB0fJVaIF_0bJ5L_AKS-st5pk9VjaiGXyfQ3nd6YrR2_X4r1vgHtMNFf1Lvz9F_R6S-64Nm_63-PitYBNrzVwfaR0bqpTfhBjs0EndSr9jOvBzPVAOB5xHTkRXQgjCkhHJY4ii49Pk/s320/%2560Screenshot.png&quot; width=&quot;242&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
I tried it using base line attribute of Relative Layout.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;First&amp;nbsp;adjust the size of view:&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;@Override&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;super.onMeasure(widthMeasureSpec, heightMeasureSpec);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;//Height should be always width * 7 / 12&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()*7/12);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;Then Override the getBaseLine method:&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;@Override&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;public int getBaseline() {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;//base line is from bottom to width/12 (radius of the blue circle)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;return getMeasuredHeight()-getMeasuredWidth()/12;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;Following onDraw method would explain the reason for the above calculation:&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;@Override&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;protected void onDraw(Canvas canvas) {&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;Paint paint = new Paint();&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;paint.setAntiAlias(true);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;//Draw the half circle&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;paint.setColor(Color.GRAY);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;float width = getWidth();&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;float height = getHeight();&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;canvas.save();&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;canvas.translate(width/2, height-width/12);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;canvas.drawArc(new RectF(-width/3, -width/3, +width/3, width/3), 0, -180, true, paint);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;//Draw small circles&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;paint.setColor(Color.DKGRAY);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;RectF rectF = new RectF(-width/2+width/24, -width/12+width/24, -width/3-width/24, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+width/12-width/24);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;canvas.drawOval(rectF, paint);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;for(int i = 0 ; i &amp;lt; 15 ;i++){&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;canvas.rotate(12f);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;canvas.drawOval(rectF, paint);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;}&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;//Draw blue circle&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;paint.setColor(Color.BLUE);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;canvas.rotate(-180+30);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;canvas.drawOval(new RectF(-width/2, -width/12, -width/3, +width/12), paint);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;//Draw red arrow&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;paint.setColor(Color.RED);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;Path path = new Path();&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;path.moveTo(-width*5/12, 0);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;path.lineTo(10, -width/12);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;path.lineTo(0, 0);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;path.lineTo(10, +width/12);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;path.close();&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;canvas.drawPath(path, paint);&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;canvas.restore();&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;Finally, create a layout xml as following:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;br /&gt;
&amp;lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;android:orientation=&quot;vertical&quot; android:layout_width=&quot;fill_parent&quot;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;android:layout_height=&quot;fill_parent&quot;&amp;gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;lt;demo.ui.testing.DemoUITesting&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;android:layout_height=&quot;fill_parent&quot; android:layout_width=&quot;fill_parent&quot;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000;&quot;&gt;android:layout_alignBaseline=&quot;@+id/radioButton1&quot;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;android:layout_toRightOf=&quot;@+id/radioButton1&quot;&amp;gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;lt;RadioButton android:layout_width=&quot;wrap_content&quot;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;android:layout_height=&quot;wrap_content&quot; android:id=&quot;@+id/radioButton1&quot;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;android:layout_centerVertical=&quot;true&quot;&amp;gt;&lt;br /&gt;
&amp;lt;/RelativeLayout&amp;gt;&lt;br /&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
Enjoy!.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sudarnimalan.blogspot.com/feeds/6249659917056274312/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/9106967537835418775/6249659917056274312' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/6249659917056274312'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9106967537835418775/posts/default/6249659917056274312'/><link rel='alternate' type='text/html' href='http://sudarnimalan.blogspot.com/2011/09/android-aligning-custom-views-at-base.html' title='Android: Aligning Custom Views at Base Line'/><author><name>Sudar Nimalan</name><uri>http://www.blogger.com/profile/10336203369195814559</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0qUB0fJVaIF_0bJ5L_AKS-st5pk9VjaiGXyfQ3nd6YrR2_X4r1vgHtMNFf1Lvz9F_R6S-64Nm_63-PitYBNrzVwfaR0bqpTfhBjs0EndSr9jOvBzPVAOB5xHTkRXQgjCkhHJY4ii49Pk/s72-c/%2560Screenshot.png" height="72" width="72"/><thr:total>1</thr:total></entry></feed>