Reputation: 617
I have working on a screen to display a fixed footer and a another content with scrollview. But the content was not scrolling.
below is my code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relateId"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:background="#689F38"
android:gravity="center">
<TextView
android:id="@+id/header_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="header_msg"
android:textColor="#FFFFFF"
android:textSize="25sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="#689F38"
android:gravity="center">
<TextView
android:id="@+id/footer_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="footer"
android:textColor="#FFFFFF"
android:textSize="25sp" />
</RelativeLayout>
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/footer"
android:layout_below="@+id/header"
android:fillViewport="true">
<LinearLayout
android:id="@+id/myLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:fillViewport="true"
android:orientation="vertical">
<TextView
android:id="@+id/bodytext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/large_text"
android:textColor="#F44336"
android:textSize="25sp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
below are the screen shots. That I was getting
below is the picture that I was getting after scroll
As shown in the above pictures, The foorter is not sticking to screen. When I use the above code the content was displaying upto the screen size. after the I am unable scroll to view remaining content. Don't know the exact problem. Please some one help me.
Upvotes: 2
Views: 91
Reputation: 58964
sample.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relateId"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="center"
android:background="#689F38"
android:gravity="center">
<TextView
android:id="@+id/header_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="header_msg"
android:textColor="#FFFFFF"
android:textSize="25sp"/>
</RelativeLayout>
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<LinearLayout
android:id="@+id/myLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:fillViewport="true"
android:orientation="vertical">
<TextView
android:id="@+id/bodytext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/large_text"
android:textColor="#F44336"
android:textSize="25sp"/>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="center"
android:background="#689F38"
android:gravity="center">
<TextView
android:id="@+id/footer_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="footer"
android:textColor="#FFFFFF"
android:textSize="25sp"/>
</RelativeLayout>
</LinearLayout>
Edit for your requirement
Below is full code that i tested with above xml layout.
public class ActivitySample extends BaseProject {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.kpis.structure">
<application
android:name="in.kpis.structure.appClasses.ApplicationContext"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"
>
<activity android:name=".appClasses.activities.ActivitySample">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
in res>values>styles.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
//....other styles
</resources>
Upvotes: 2