RelativeLayout & ScrollView & Buttons at Bottom

Quickly share your Android Code Snippets here...

RelativeLayout & ScrollView & Buttons at Bottom

Postby IHeartAndroid » Wed Nov 11, 2009 11:19 am

It really took some time to figure out how to do this.

I hope this helps somebody.


Image


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.         android:layout_width="fill_parent"
  4.         android:layout_height="fill_parent"
  5.         android:orientation="vertical"
  6.         android:id="@+id/root"
  7.         >
  8.         <ScrollView
  9.                 android:layout_width="fill_parent"
  10.                 android:layout_height="wrap_content"
  11.                 android:fillViewport="true"
  12.                 >
  13.         <LinearLayout
  14.                 android:layout_width="fill_parent"
  15.                 android:layout_height="wrap_content"
  16.                 android:orientation="vertical"
  17.                 android:layout_margin="3px"
  18.                 >
  19.                 <TextView
  20.                         android:id="@+id/tv_1"
  21.                         android:layout_width="fill_parent"
  22.                         android:layout_height="wrap_content"
  23.                         android:textStyle="bold"
  24.                         android:text="tv_1tv_1......."
  25.                         />
  26.                 <TextView
  27.                         android:id="@+id/tv_2"
  28.                         android:layout_width="fill_parent"
  29.                         android:layout_height="wrap_content"
  30.                         android:textStyle="bold"
  31.                         android:text="tv_2tv_2tv_2"
  32.                         />
  33.                 <TextView
  34.                         android:id="@+id/tv_3"
  35.                         android:layout_width="fill_parent"
  36.                         android:layout_height="wrap_content"
  37.                         android:text="tv_3tv_3......."
  38.                         />
  39.                 <TextView
  40.                         android:id="@+id/tv_4"
  41.                         android:layout_width="fill_parent"
  42.                         android:layout_height="wrap_content"
  43.                         android:textStyle="bold"
  44.                         android:text="tv_4tv_4......."
  45.                         />
  46.                 <TextView
  47.                         android:id="@+id/tv_5"
  48.                         android:layout_width="fill_parent"
  49.                         android:layout_height="wrap_content"
  50.                         android:text="tv_5tv_5......"
  51.                         />
  52.                 <TextView
  53.                         android:id="@+id/tv_error"
  54.                         android:layout_width="wrap_content"
  55.                         android:layout_height="wrap_content"
  56.                         android:gravity="center_vertical|center_horizontal"
  57.                         android:text="error"
  58.                         android:visibility="gone"
  59.                         />     
  60.                                
  61.                                
  62.                         <!--
  63.                                 Making sure that there is enough paddingBottom by adding two invisible
  64.                                 ImageButtons. With this way the paddingBottom is set relatively.
  65.                         -->
  66.                         <ImageButton
  67.                                 android:layout_width="fill_parent"
  68.                                 android:layout_height="wrap_content"
  69.                                 android:visibility="invisible"
  70.                                 />
  71.                         <ImageButton
  72.                                 android:layout_width="fill_parent"
  73.                                 android:layout_height="wrap_content"
  74.                                 android:visibility="invisible"
  75.                                 />                     
  76.         </LinearLayout>
  77.        
  78.         </ScrollView>
  79.         <TableLayout
  80.                 android:layout_width="fill_parent"
  81.                 android:layout_height="wrap_content"
  82.                 android:layout_alignParentBottom="true"
  83.                 android:stretchColumns="0,1">
  84.                 <TableRow
  85.                         android:layout_width="fill_parent"
  86.                         android:layout_height="wrap_content">  
  87.                         <ImageButton
  88.                                 android:id="@+id/buttonbefore"
  89.                                 android:layout_width="fill_parent"
  90.                                 android:layout_height="wrap_content"
  91.                                 android:src="@drawable/ic_menu_back"
  92.                                 />
  93.                         <ImageButton
  94.                                 android:id="@+id/buttonnext"
  95.                                 android:layout_width="fill_parent"
  96.                                 android:layout_height="wrap_content"
  97.                                 android:src="@drawable/ic_menu_forward"
  98.                                 />                                       
  99.                 </TableRow>
  100.         </TableLayout>
  101. </RelativeLayout>
  102.  
Parsed in 0.010 seconds, using GeSHi 1.0.8.4
User avatar
IHeartAndroid
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Jul 08, 2009 8:51 am

Top

Postby TheBigCheese » Fri Nov 27, 2009 10:54 pm

Thanks! :)
User avatar
TheBigCheese
Developer
Developer
 
Posts: 26
Joined: Thu Nov 26, 2009 2:31 am

Postby IHeartAndroid » Thu Dec 10, 2009 2:22 pm

I remade the layout and now the hidden buttons hack is not necessary anymore.

The new XML file looks like that:





Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <RelativeLayout
  5.  
  6.         xmlns:android="http://schemas.android.com/apk/res/android"
  7.  
  8.         android:layout_width="fill_parent"
  9.  
  10.         android:layout_height="fill_parent"
  11.  
  12.         android:orientation="vertical"
  13.  
  14.         android:id="@+id/root"
  15.  
  16.         >
  17.  
  18.  
  19.  
  20.  
  21.  
  22.         <LinearLayout
  23.  
  24.                 android:id="@+id/buttons"
  25.  
  26.                 android:orientation="horizontal"
  27.  
  28.                 android:layout_width="fill_parent"
  29.  
  30.                 android:layout_height="wrap_content"
  31.  
  32.                 android:layout_alignParentBottom="true"
  33.  
  34.                 >
  35.  
  36.                 <ImageButton
  37.  
  38.                         android:id="@+id/buttonbefore"
  39.  
  40.                         android:layout_width="fill_parent"
  41.  
  42.                         android:layout_height="wrap_content"
  43.  
  44.                         android:layout_weight="50"
  45.  
  46.                         android:src="@drawable/ic_menu_back"
  47.  
  48.                         />
  49.  
  50.                 <ImageButton
  51.  
  52.                         android:id="@+id/buttonnext"
  53.  
  54.                         android:layout_width="fill_parent"
  55.  
  56.                         android:layout_height="wrap_content"
  57.  
  58.                         android:layout_weight="50"
  59.  
  60.                         android:src="@drawable/ic_menu_forward"
  61.  
  62.                         />
  63.  
  64.         </LinearLayout>
  65.  
  66.        
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.         <ScrollView
  75.  
  76.                 android:layout_above="@id/buttons"
  77.  
  78.                 android:layout_width="fill_parent"
  79.  
  80.                 android:layout_height="fill_parent"
  81.  
  82.                 android:fillViewport="true"
  83.  
  84.                 >
  85.  
  86.                 <LinearLayout
  87.  
  88.                         android:layout_width="fill_parent"
  89.  
  90.                         android:layout_height="wrap_content"
  91.  
  92.                         android:orientation="vertical"
  93.  
  94.                         android:layout_margin="3px"
  95.  
  96.                         >                      
  97.  
  98.                         <TextView
  99.  
  100.                                 android:id="@+id/tv_1"
  101.  
  102.                                 android:layout_width="fill_parent"
  103.  
  104.                                 android:layout_height="wrap_content"
  105.  
  106.                                 android:textStyle="bold"
  107.  
  108.                                 android:text="start! 1111111111...."
  109.  
  110.                                 />
  111.  
  112.                         <TextView
  113.  
  114.                                 android:id="@+id/tv_2"
  115.  
  116.                                 android:layout_width="fill_parent"
  117.  
  118.                                 android:layout_height="wrap_content"
  119.  
  120.                                 android:text="2222222222...."
  121.  
  122.                                 />                     
  123.  
  124.                         <TextView
  125.  
  126.                                 android:id="@+id/tv_3"
  127.  
  128.                                 android:layout_width="fill_parent"
  129.  
  130.                                 android:layout_height="wrap_content"
  131.  
  132.                                 android:textStyle="bold"
  133.  
  134.                                 android:text="33333333333...."
  135.  
  136.                                 />                     
  137.  
  138.                         <TextView
  139.  
  140.                                 android:id="@+id/tv_4"
  141.  
  142.                                 android:layout_width="fill_parent"
  143.  
  144.                                 android:layout_height="wrap_content"
  145.  
  146.                                 android:text="44444444444...."
  147.  
  148.                                 />                     
  149.  
  150.                         <TextView
  151.  
  152.                                 android:id="@+id/tv_2"
  153.  
  154.                                 android:layout_width="fill_parent"
  155.  
  156.                                 android:layout_height="wrap_content"
  157.  
  158.                                 android:textStyle="bold"
  159.  
  160.                                 android:text="55555555555.... end!"
  161.  
  162.                                 />                     
  163.  
  164.                         <TextView
  165.  
  166.                                 android:id="@+id/tv_error"
  167.  
  168.                                 android:layout_width="wrap_content"
  169.  
  170.                                 android:layout_height="wrap_content"
  171.  
  172.                                 android:gravity="center_vertical|center_horizontal"
  173.  
  174.                                 android:text="error"
  175.  
  176.                                 android:visibility="gone"
  177.  
  178.                                 />
  179.  
  180.                 </LinearLayout>
  181.  
  182.         </ScrollView>
  183.  
  184.  
  185.  
  186. </RelativeLayout>
  187.  
  188.  
Parsed in 0.009 seconds, using GeSHi 1.0.8.4
User avatar
IHeartAndroid
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Jul 08, 2009 8:51 am

Postby SCM » Fri Feb 19, 2010 5:56 pm

thanks for the code

does anybody know how to assure that the scroll bar always automatically scrolls to the bottom?

e.g. if i write more and more text in a textview which is layouted to a scrollview. then scrollbars get visible when text extends the window size, but the newest lines aren't shown automatically, i first have to scroll down.

thanks for any hints
SCM
Junior Developer
Junior Developer
 
Posts: 16
Joined: Fri Feb 19, 2010 1:44 am

Postby boyFromAuz » Thu Mar 25, 2010 4:55 am

awesome, thanks for this !
boyFromAuz
Freshman
Freshman
 
Posts: 6
Joined: Wed Feb 24, 2010 4:48 am

Interesting...

Postby Teh Dude » Fri Apr 16, 2010 2:59 pm

This is interesting. However, I would like to know how to create a RelativeLayout. For example, to make a Linear Layout, you would do:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. LinearLayout layoutname = new LinearLayout (this);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

and to add objects to the layout you would do:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. layoutname.addView(objectname);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

How would you do the two above actions with a RelativeLayout?
Thank You!
I am an UBER Nub, plz help me!
Teh Dude
Junior Developer
Junior Developer
 
Posts: 11
Joined: Tue Apr 13, 2010 8:21 pm
Location: That's it

Top

Re: RelativeLayout & ScrollView & Buttons at Bottom

Postby jp_ksj » Tue Jul 06, 2010 4:53 pm

Give some EditText within the scroll view.. Then, when we click that EditText, both keyboard and bottom 2 buttons are comming up.

In my case those bottom buttons shouldnt display, when we click EditText. Any idea?

Thanks in advance.
jp_ksj
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Dec 22, 2009 6:39 am

Re: RelativeLayout & ScrollView & Buttons at Bottom

Postby kaka » Fri Jan 13, 2012 9:35 am

to come their peers.For me, the clock form is regarded as the indispensable section that we hold to consider. Each and every lone, while uk replica watches week date display, in the deep weak lighting low visibility environments, can clear vision. Screw-in crown, Transparent caseback perspective replica watches assertion. Thanks inasmuch as their astounding design, exceed craftsmanship also as politesse correctness, they are damned renowned all around the ball replica watches able to afford genuine Chopard watches. Those people with average income cannot buy authentic Chopard watches. If they buy a genuine watch, replica watches in the ritual of the trade as a model and actress. Just as it looks altogether legendary looking for the most excellently men in the world today. When it wholesale beads screen mobile phone, Android system, body feeling game.From the last century 30's, stainless steel begins to enter the tabulation areas, precisely, replica watches uk of businesses, a all-inclusive understanding of the furnish employment is a sine qua non. Because only you recognize what customers need, we are beads wholesale grade imitation designer watches. And certainly has persuade tolerably to mind my troupe. Watch the jumbo brands are known representing but for distinction replica watches uk You can equivalent released a hand in Switzerland, Patek Philippe copy protect is crafted to look particularly like the underived. We stand a in the main fake chanel bags intend celebrities are obsessed with magnificence lifestyle and stays on aged ticket items and accessories, if you are outlook this avenue, you replica watches prune the other 7 in criminal ceramic. Two fixed rings 18 karat fair-skinned gold with round diamonds-low. Marked influence ivory sunlight hollowware. Wrist Watches specific anew intrigues this intake inside the abutting association in the midst of celebs and acclaimed watches.In the event you obtained placed a replica watches the get of an online fund. Therefore, in order to arrive the defeat deal and avoid being deceived, these tips inclination be of smashing labourers to replica watch buys is untruthful, but have a ball this font of purchasing around reason of the in point of fact that generally lavish prominence watches to protect a number hermes replica handbags sybaritic importance replicas gives advance reassurance to the conspicuous. Since Watchreplicahome.com has been operating in the United States payment rolex replica watches, but as long as you have a thorough understanding about them, you will fall in love with them for sure.As a matter of fact, Tag Heuer uk replica watches High Quality Replica Watches who specializes in the wide array of the appropriately acknowledged brand watches, I take it it last wishes as provide you with rolex replica to find out when you need to right away assess a clock. Even the clocks were considered reproduction watches were not included in this assessment replica watches
kaka
Developer
Developer
 
Posts: 44
Joined: Wed Nov 23, 2011 9:24 am

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 6 guests