Beginner
Beginner

Reputation: 29533

Android - XML button goes missing?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bkgrnd">
    <RelativeLayout
        android:id="@+id/RelativeLayout01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
        <ImageView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/ImageView_MenuHeader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/logo"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"></ImageView>
        <TextView
            android:id="@+id/TextView01"
            android:layout_height="wrap_content"
            android:text="@string/admin"
            android:textSize="@dimen/screen_title_size"
            android:shadowDx="0"
            android:shadowDy="0"
            android:shadowRadius="10"
            android:layout_width="wrap_content"
            android:layout_gravity="fill_horizontal|center"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:shadowColor="@android:color/white"
            android:textColor="@color/title_color"></TextView>
        <ImageView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/ImageView_MenuHeader2"
            android:layout_height="wrap_content"
            android:src="@drawable/logo"
            android:layout_gravity="right|center_vertical"
            android:layout_width="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"></ImageView>
    </RelativeLayout>    
    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:isScrollContainer="true"
        android:scrollbars="vertical"
        android:scrollbarAlwaysDrawVerticalTrack="true">
        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">     
            <Spinner
                android:id="@+id/Spinner_Table"
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:drawSelectorOnTop="true"></Spinner>
             <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="@dimen/help_text_size"
                android:textStyle="bold"
                android:gravity="center"
                android:id="@+id/Blank"></TextView>
            <TextView  
                android:id="@+id/admintable" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"></TextView>
            </LinearLayout>
    </ScrollView>
    <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent">  
             <Button 
                android:id="@+id/Logout" 
                android:text="@string/Logout" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"></Button>
    </RelativeLayout>
 </LinearLayout>

All of the above xml is within a liner layout...The problem is when the text view admin table get written data too in the application there is a large amount of data shown...the data shows fine...however when the user scrolls to the bottom of the screen they should see the logout button, but it is not showing?

Upvotes: 1

Views: 1038

Answers (2)

DanO
DanO

Reputation: 10270

Try setting the ScrollView layout_height to something static like 60dp and set the layout_weight to 1.0 which will cause it to expand to its maximum without going off the screen.

<ScrollView
    android:id="@+id/ScrollView01"
    android:layout_width="fill_parent"
    android:layout_height="60dp"
    android:layout_weight="1.0"
    android:isScrollContainer="true"
    android:scrollbars="vertical"
    android:scrollbarAlwaysDrawVerticalTrack="true">
    ...
</ScrollView>

This however should cause the Logout button to show up all the time below the ScrollView.

In order to get the button to appear at the bottom of the ScrollView try moving the RelativeLayout inside the ScrollView and nesting them in another LinearLayout like so:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bkgrnd">
    <RelativeLayout
        android:id="@+id/RelativeLayout01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
        ... your header views ...
    </RelativeLayout>    
    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:isScrollContainer="true"
        android:scrollbars="vertical"
        android:scrollbarAlwaysDrawVerticalTrack="true">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">     
            <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">     
                ... data you load ...
            </LinearLayout>
            <RelativeLayout
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent">  
                 <Button 
                    android:id="@+id/Logout" 
                    android:text="@string/Logout" 
                    android:layout_width="wrap_content" 
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"></Button>
            </RelativeLayout>
        </LinearLayout>
    </ScrollView>
 </LinearLayout>

Upvotes: 1

Macarse
Macarse

Reputation: 93133

Some comments:

You don't need to define widgets like this:

 <Button 
                android:id="@+id/Logout" 
                android:text="@string/Logout" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"></Button>

You can do it like this:

 <Button 
                android:id="@+id/Logout" 
                android:text="@string/Logout" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"/>

From my point of view, the issue you are having is that the ScrollView is taking all the space left.

Try defining the RelativeLayout with the Button first and tell the ScrollView to be android:layout_above the RelativeLayout.

Upvotes: 0

Related Questions