Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 6th, 2012  |  syntax: None  |  size: 4.43 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Fixing content at the bottom of the screen in Android
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  4.     android:id="@+id/ScrollView01"
  5.     android:layout_width="fill_parent"
  6.     android:layout_height="wrap_content"
  7.     android:fillViewport="true" >
  8.  
  9.     <LinearLayout
  10.         android:layout_width="fill_parent"
  11.         android:layout_height="0dp"
  12.         android:orientation="vertical" >
  13.  
  14.         <LinearLayout
  15.             android:layout_width="match_parent"
  16.             android:layout_height="0dp"
  17.             android:layout_gravity="center_horizontal"
  18.             android:layout_weight="1"
  19.             android:gravity="center_horizontal" >
  20.  
  21.             <TextView ... />
  22.  
  23.             ...
  24.  
  25.             <TextView ... />
  26.  
  27.         </LinearLayout>
  28.  
  29.         <Button
  30.             android:id="@+id/ButtonMain"
  31.             android:layout_width="fill_parent"
  32.             android:layout_height="0dp"
  33.             android:layout_gravity="center_horizontal"
  34.             android:layout_marginLeft="5dp"
  35.             android:layout_marginRight="5dp"
  36.             android:layout_weight="1"
  37.             android:text="@string/button_text"
  38.             android:textSize="30px"
  39.             android:textStyle="bold"
  40.             android:width="200px" />
  41.  
  42.     </LinearLayout>
  43.  
  44. </ScrollView>
  45.        
  46. android:layout_alignParentBottom="true"
  47.        
  48. <?xml version="1.0" encoding="utf-8"?>
  49. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  50.     android:id="@+id/scroller"
  51.     android:layout_width="fill_parent"
  52.     android:layout_height="fill_parent"
  53.     android:fillViewport="true" >
  54.  
  55.     <LinearLayout
  56.         android:layout_width="fill_parent"
  57.         android:layout_height="wrap_content"
  58.         android:gravity="center_horizontal"
  59.         android:orientation="vertical" >
  60.  
  61.         <TextView
  62.             android:id="@+id/txt1"
  63.             android:layout_width="fill_parent"
  64.             android:layout_height="wrap_content"
  65.             android:gravity="center"
  66.             android:text="Hello"
  67.             android:textSize="25sp" />
  68.  
  69.         <TextView
  70.             android:id="@+id/txt2"
  71.             android:layout_width="fill_parent"
  72.             android:layout_height="wrap_content"
  73.             android:gravity="center"
  74.             android:text="Hello2"
  75.             android:textSize="25sp" />
  76.  
  77.         <LinearLayout
  78.             android:layout_width="fill_parent"
  79.             android:layout_height="fill_parent"
  80.             android:gravity="bottom|center"
  81.             android:orientation="horizontal" >
  82.  
  83.             <Button
  84.                 android:id="@+id/ButtonMain"
  85.                 android:layout_width="fill_parent"
  86.                 android:layout_height="wrap_content"
  87.                 android:layout_marginLeft="5dp"
  88.                 android:layout_marginRight="5dp"
  89.                 android:text="click me"
  90.                 android:textSize="30px"
  91.                 android:textStyle="bold" />
  92.         </LinearLayout>
  93.     </LinearLayout>
  94.  
  95. </ScrollView>
  96.        
  97. <?xml version="1.0" encoding="utf-8"?>
  98. <LinearLayout
  99.     xmlns:android="http://schemas.android.com/apk/res/android"
  100.     android:layout_width="match_parent"
  101.     android:layout_height="match_parent"
  102.     android:orientation="vertical" >
  103.  
  104.     <ScrollView
  105.         android:id="@+id/ScrollView01"
  106.         android:layout_width="match_parent"
  107.         android:layout_height="0dp"
  108.         android:layout_weight="1"
  109.         android:fillViewport="true" >
  110.  
  111.         <!-- You can remove one of these two LinearLayouts, since they just nest each other. Which one you want to remove is up to you. -->
  112.         <LinearLayout
  113.             android:layout_width="match_parent"
  114.             android:layout_height="match_parent"
  115.             android:orientation="vertical" >
  116.  
  117.             <LinearLayout
  118.                 android:layout_width="match_parent"
  119.                 android:layout_height="wrap_content"
  120.                 android:layout_gravity="center_horizontal"
  121.                 android:gravity="center_horizontal" >
  122.  
  123.                 <TextView ... />
  124.  
  125.                 ...
  126.  
  127.                 <TextView ... />
  128.  
  129.             </LinearLayout>
  130.  
  131.         </LinearLayout>
  132.  
  133.     </ScrollView>
  134.  
  135.     <Button
  136.         android:id="@+id/ButtonMain"
  137.         android:layout_width="match_parent"
  138.         android:layout_height="wrap_content"
  139.         android:layout_marginLeft="5dp"
  140.         android:layout_marginRight="5dp"
  141.         android:text="@string/button_text"
  142.         android:textSize="30px"
  143.         android:textStyle="bold"
  144.         android:width="200px" />
  145.  
  146. </LinearLayout>