Search code examples
androidxmlhorizontalscrollview

Adding a horizontalScrollView to bottom navigation bar


I have an activity which contains a table layout and below it I have some buttons, I then implemented a sort of navigation bar using radio group and radio buttons. What I want to do is add a horizontal scroll view to this radio group, however when I try to add it the navigation bar just changes position to the top of the activity to collapse with the table layout and I need this navigation bar to stick to the bottom of the activity. Any help would be much appreciated. Thanks in advance.

Here's my xml code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bckgroundchinese"
    android:id="@+id/bottom_layout" >


    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        android:scrollbarFadeDuration="0"
        android:scrollbarSize="12dip" >

        <HorizontalScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:background="#3b3b3b" >

            <TableLayout
                android:id="@+id/myTableLayout"
                android:layout_width="match_parent"
                android:layout_height="276dp"
                android:background="@drawable/bckgroundchinese" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="NO PATIENTS" />
            </TableLayout>
        </HorizontalScrollView>
    </ScrollView>


    <Button
        android:id="@+id/patient"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/radioGroup1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:background="@drawable/buttonchinese"
        android:text="Add Patient" />

    <Button
        android:id="@+id/signtOutDr"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/patient"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:background="@drawable/buttonchinese"
        android:text="sign out" />


     <Button
        android:id="@+id/info"
        android:layout_width="450dp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_above="@+id/alerts"
        android:background="@drawable/buttonchinese"
        android:text="Edit My Information" />


    <Button
        android:id="@+id/alerts"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/signtOutDr"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:background="@drawable/buttonchinese"
        android:text="View Alerts" />
    <!-- 
     <HorizontalScrollView
        android:id="@+id/scrollView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbarFadeDuration="0"
        android:scrollbarSize="5dip" >
     -->


     <RadioGroup
         android:id="@+id/radioGroup1"
         android:layout_width="fill_parent"
         android:layout_height="71dp"
         android:layout_alignParentBottom="true"
         android:layout_alignParentLeft="true"
         android:background="@drawable/bckgroundchinese"
         android:orientation="horizontal" >

         <RadioButton
             android:id="@+id/btnAll"
             style="@style/navbar_button"
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"
             android:drawableTop="@drawable/navbar_allselector"
             android:gravity="bottom|center_horizontal"
             android:text="My Patients" />

         <RadioButton
             android:id="@+id/btnPicture"
             style="@style/navbar_button"
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"
             android:layout_marginLeft="5dp"
             android:drawableTop="@drawable/doctoricon"
             android:text="View Assistants" />

         <RadioButton
             android:id="@+id/btnVideo"
             style="@style/navbar_button"
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"
             android:layout_marginLeft="5dp"
             android:drawableTop="@drawable/records"
             android:text="Add Assistants" />

         <RadioButton
             android:id="@+id/btnFile"
             style="@style/navbar_button"
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"
             android:layout_marginLeft="5dp"
             android:drawableTop="@drawable/phonebook_"
             android:text="Add Patient" />

         <RadioButton
             android:id="@+id/btnEditInfo"
             style="@style/navbar_button"
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"
             android:layout_marginLeft="5dp"
             android:drawableTop="@drawable/phonebook_"
             android:text="Edit My Info" />
     </RadioGroup>
     <!-- </HorizontalScrollView> -->

</RelativeLayout>

Solution

  • you need to move those properties:

     android:layout_alignParentBottom="true"
     android:layout_alignParentLeft="true"
    

    from the RadioGroup to the HorizontalScrollView, Like this:

     <HorizontalScrollView
        android:id="@+id/scrollView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:scrollbarFadeDuration="0"
        android:scrollbarSize="5dip" >
    
     <RadioGroup
         android:id="@+id/radioGroup1"
         android:layout_width="fill_parent"
         android:layout_height="71dp"
         android:background="@drawable/bckgroundchinese"
         android:orientation="horizontal" >
    
         <RadioButton
             android:id="@+id/btnAll"
             style="@style/navbar_button"
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"
             android:drawableTop="@drawable/navbar_allselector"
             android:gravity="bottom|center_horizontal"
             android:text="My Patients" />
    
         <RadioButton
             android:id="@+id/btnPicture"
             style="@style/navbar_button"
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"
             android:layout_marginLeft="5dp"
             android:drawableTop="@drawable/doctoricon"
             android:text="View Assistants" />
    
         <RadioButton
             android:id="@+id/btnVideo"
             style="@style/navbar_button"
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"
             android:layout_marginLeft="5dp"
             android:drawableTop="@drawable/records"
             android:text="Add Assistants" />
    
         <RadioButton
             android:id="@+id/btnFile"
             style="@style/navbar_button"
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"
             android:layout_marginLeft="5dp"
             android:drawableTop="@drawable/phonebook_"
             android:text="Add Patient" />
    
         <RadioButton
             android:id="@+id/btnEditInfo"
             style="@style/navbar_button"
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"
             android:layout_marginLeft="5dp"
             android:drawableTop="@drawable/phonebook_"
             android:text="Edit My Info" />
     </RadioGroup>