Viewpager fragments not overlapping activity elements - android

I have a activity where i have some images,textview,a button and viewpager. Viewpager has height and width to match parent and all the layouts have background as white color . Now when the activity loads viewpager gets its fragments by adapter and it loads fragments. Now the images,textview are hidden behind the loaded fragments but the button does not gets hidden and its shown in fragments. Why is this happening ?
THis is my layout of activity with viewpager as last element
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.appointmentno.android.LogoFrontScreen"
android:background="#android:color/white"
android:keepScreenOn="true">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:id="#+id/rel_center_logo">
<ImageView
android:layout_width="#dimen/logo_width"
android:layout_height="#dimen/logo_height"
android:src="#drawable/finalc"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:id="#+id/img_logo_c"/>
<TextView
android:layout_width="210dp"
android:layout_height="wrap_content"
android:text="#string/logo_name"
android:layout_below="#id/img_logo_c"
android:id="#+id/app_name"
style="#style/RobotoTextViewStyle"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textSize="#dimen/logo_text_size"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/logo_underline"
android:layout_below="#id/app_name"
android:id="#+id/app_name_underline"
style="#style/RobotoTextViewStyle"
android:textColor="#android:color/black"
android:textSize="13sp"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt_progress_report"
android:layout_below="#+id/rel_center_logo"
android:gravity="center"
android:layout_marginTop="50dp"
android:layout_centerHorizontal="true"
android:maxLines="10"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/str_2"
android:id="#+id/btn_enter_app"
android:layout_below="#id/rel_center_logo"
android:layout_centerHorizontal="true"
android:layout_marginTop="84dp"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:id="#+id/logo_screen_progress"
android:layout_below="#id/rel_center_logo"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
android:id="#+id/txt_ver_alert"
android:gravity="center"/>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager_gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
</RelativeLayout>

Try this:
<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"
tools:context="com.appointmentno.android.LogoFrontScreen"
android:background="#android:color/white"
android:keepScreenOn="true"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:id="#+id/rel_center_logo"
android:orientation="vertical">
<ImageView
android:layout_width="#dimen/logo_width"
android:layout_height="#dimen/logo_height"
android:src="#drawable/finalc"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:id="#+id/img_logo_c"/>
<TextView
android:layout_width="210dp"
android:layout_height="wrap_content"
android:text="#string/logo_name"
android:id="#+id/app_name"
style="#style/RobotoTextViewStyle"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textSize="#dimen/logo_text_size"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/logo_underline"
android:id="#+id/app_name_underline"
style="#style/RobotoTextViewStyle"
android:textColor="#android:color/black"
android:textSize="13sp"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:id="#+id/rel_center_logo"
android:orientation="vertical"
android:layout_below="#id/rel_center_logo">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt_progress_report"
android:gravity="center"
android:layout_marginTop="50dp"
android:layout_centerHorizontal="true"
android:maxLines="10"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/str_2"
android:id="#+id/btn_enter_app"
android:layout_centerHorizontal="true"
android:layout_marginTop="84dp"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:id="#+id/logo_screen_progress"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
android:id="#+id/txt_ver_alert"
android:gravity="center"/>
</LinearLayout>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager_gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
</RelativeLayout>
I basically divided your views into to groups (according to what I believe you want) and put them into their respective LinearLayouts. So in the end you have one RelativeLayout that holds two LinearLayouts and a ViewPager.

Related

How to limit the amount of space Framelayout takes on screen?

I have created a fragment which displays a bunch of different text. Each time the activity is loaded the text is different. I load this fragment in main activity using a framelayout. At the bottom of my main screen I have created a buttons panel with three buttons with each performing a different action such as play and next item. The problem is that some times when the text data is big and the framelayout expands to the bottom of the screen. How can I limit Framelayout to remain above buttons panel?
In the fragment layout I have multiple TextViews nested in a ScrollView.
fragment.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".fragments.TextsFragment">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/english_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
tools:text="English Name"
android:textAppearance="?android:textAppearanceMedium"/>
<TextView
android:id="#+id/orignal_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
tools:text="Original Name"
android:textAppearance="?android:textAppearanceMedium"/>
<TextView
android:id="#+id/translatied_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
tools:text="Translated Name"
android:textAppearance="?android:textAppearanceMedium"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/opening_braces"
android:textAppearance="?android:textAppearanceMedium"/>
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
tools:text="2"
android:textAppearance="?android:textAppearanceMedium"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="#string/colon"
android:textAppearance="?android:textAppearanceMedium"/>
<TextView
android:id="#+id/line_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
tools:text="42"
android:textAppearance="?android:textAppearanceMedium"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/closing_braces"
android:textAppearance="?android:textAppearanceMedium"/>
</LinearLayout>
<TextView
android:id="#+id/word"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
tools:text="Word"
android:textAppearance="?android:textAppearanceMedium"/>
<TextView
android:id="#+id/english_translation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
tools:text="English Translation"
android:textAppearance="?android:textAppearanceMedium"/>
</LinearLayout>
</ScrollView>
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.MainActivity">
<FrameLayout
android:id="#+id/text_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
<RelativeLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_alignParentBottom="true">
<ImageButton
android:id="#+id/play_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/white_play_button"
android:contentDescription="#string/play"
android:onClick="onClickPlayButton"
android:layout_alignParentStart="true"
/>
<TextView
android:id="#+id/textView3"
android:layout_width="170dp"
android:layout_height="52dp"
android:text="Random"
android:background="#drawable/border"
android:includeFontPadding="false"
android:gravity="center"
android:layout_toEndOf="#id/play_button"
android:layout_alignTop="#id/play_button"/>
<ImageButton
android:id="#+id/share_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/white_share_button"
android:contentDescription="#string/share"
android:onClick="onClickShareButton"
android:layout_toEndOf="#id/textView3" />
<ImageButton
android:id="#+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/white_next_button"
android:contentDescription="#string/next"
android:onClick="onClickNextButton"
android:layout_toRightOf="#+id/share_button"/>
</RelativeLayout>
</RelativeLayout>
Is there a way to keep framelayout just above the buttons panel at bottom instead of expanding to bottom of screen?
How can I limit Framelayout to remain above buttons panel?
You can tell the surrounding RelativeLayout to make sure the FrameLayout stays above the buttons panel by using the attribute android:layout_above for the FrameLayout
<FrameLayout
android:id="#+id/text_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#+id/linearLayout"/>
See the documentation for RelativeLayout to find out more about layout attributes

Layout_height doesn't want to gradually wrap contents when fragment are being used

What i want to accomplish is to create rating section like Google Play Store, i managed to display all the stars and review(for user to comment) but whenever the user type on it, the layout height of the RelativeLayout on my activity doesn't wrap the layout of the fragment within a fragment. I tried changing the height in any means, but still nothing solve the problem. The thing is when i make my TabLayout visible, it follows the height, but not my custom ViewPager.
I do not know whether i did it right or wrong or entirely impossible, please show me the right way. Thank you.
activity_view_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.hybridelements.recyclerview.ViewItem">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/singleImageView"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="29dp"
app:srcCompat="#drawable/android" />
<TextView
android:id="#+id/lblTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lblTitle"
android:layout_alignBottom="#+id/itemName"
android:textSize="16sp"
android:layout_marginLeft="25dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/itemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/itemName"
android:textSize="16sp"
android:layout_below="#+id/singleImageView"
android:layout_alignStart="#+id/singleImageView"/>
<TextView
android:id="#+id/lblCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lblCategory"
android:layout_alignTop="#+id/itemCategory"
android:layout_alignStart="#+id/lblTitle"
android:layout_marginRight="30dp"
android:textSize="16sp"
android:textStyle="bold"/>
<TextView
android:id="#+id/itemCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/itemCategory"
android:textSize="16sp"
android:layout_below="#+id/itemName"
android:layout_alignStart="#+id/singleImageView"
android:layout_marginTop="14dp" />
<TextView
android:id="#+id/lblRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/lblCategory"
android:layout_below="#+id/lblCategory"
android:layout_marginTop="13dp"
android:text="#string/lblRating"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/itemRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/lblRating"
android:layout_alignStart="#+id/singleImageView"
android:text="#string/itemRating"
android:textSize="16sp" />
<ImageView
android:id="#+id/imageRating"
android:layout_width="17dp"
android:layout_height="17dp"
android:layout_alignBottom="#+id/itemRating"
android:layout_alignTop="#+id/itemRating"
android:layout_gravity="center"
android:layout_toEndOf="#+id/itemRating"
android:layout_marginLeft="5dp"
app:srcCompat="#drawable/star" />
<TextView
android:id="#+id/lblDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="13dp"
android:text="#string/lblDesc"
android:textSize="16sp"
android:textStyle="bold"
android:layout_alignStart="#+id/itemDesc"
android:layout_below="#+id/itemRating"/>
<TextView
android:id="#+id/itemDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/lblDesc"
android:layout_centerHorizontal="true"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="13dp"
android:text="#string/itemDesc"
android:textSize="16sp" />
<RelativeLayout
android:id="#+id/ratingSection"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_marginTop="13dp"
android:layout_below="#+id/itemDesc"
android:background="#color/ratingSection">
<!-- Get section from fragment -->
</RelativeLayout>
<RelativeLayout
android:id="#+id/subTab"
android:layout_width="match_parent"
android:layout_height="511.84dp"
android:layout_marginTop="13dp"
android:layout_below="#+id/ratingSection">
<!-- Get section from fragment -->
</RelativeLayout>
</RelativeLayout>
</ScrollView>
fragment_sub_section_rating.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.hybridelements.openchef.fragment_activities.fragment_subs.SubSectionFragment_ReviewAndInstructions">
<RelativeLayout
android:id="#+id/main_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:visibility="gone"/>
<com.hybridelements.openchef.fragment_activities.fragment_subs.CustomSubViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/tab_layout"/>
<com.pixelcan.inkpageindicator.InkPageIndicator
android:id="#+id/fragRating_dotIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:dotDiameter="8dp"
app:dotGap="8dp"
app:animationDuration="320"
app:pageIndicatorColor="#android:color/darker_gray"
app:currentPageIndicatorColor="#android:color/black"
android:layout_alignBottom="#+id/pager"
android:layout_marginBottom="20dp"
android:visibility="gone" />
</RelativeLayout>
fragment_rating_review.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.hybridelements.openchef.fragment_activities.fragment_subs.RatingFragment_Star">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/ratingReview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/fragmentRating_reviewHeader"
android:textAlignment="center"
android:layout_marginTop="13dp"
android:textSize="16dp"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/ratingStar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/ratingReview"
android:gravity="center_horizontal">
<EditText
android:id="#+id/userRateReview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"/>
</RelativeLayout>
<Button
android:id="#+id/ratingBtnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ratingStar"
android:layout_alignParentEnd="true"
android:text="#string/ratingFrag_BtnSubmit"
style="#style/Widget.AppCompat.Button.Borderless"
android:enabled="false"/>
</RelativeLayout>
The RelativeLayout with id "ratingSection" in ratingSactivity_view_item.xml should follow the height of FrameLayout in fragment_rating_review.xml
This shouldn't happen.
This is before any typing (seems normal)
After typing, the submit button going off the screen
Try with this layout.
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:id="#+id/ratingReview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="fragmentRating_reviewHeader"
android:textAlignment="center"
android:layout_marginTop="13dp"
android:textSize="16dp"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/ratingStar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/ratingStar"
android:layout_below="#+id/ratingReview"
android:gravity="center_horizontal">
<EditText
android:id="#+id/userRateReview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"/>
</RelativeLayout>
<Button
android:id="#+id/ratingBtnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_alignParentRight="true"
android:layout_below="#+id/ratingStar"
android:text="ratingFrag_BtnSubmit"
style="#style/Widget.AppCompat.Button.Borderless"
android:enabled="false"/>
</LinearLayout>
</FrameLayout>

Relative layout views not shrinking down on smaller screen

I have an activity that hosts a fragment and a Button, the fragment should take the majority of the screen while the button should take a small part of the lower part of the screen.
However I can't make the Relative layout shrink down so that the button doesn't overlap over the fragment.
below is my activity layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_registration"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.example.activities.RegistrationActivity">
<fragment
android:name="com.example.fragments.registration.GenderFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:layout="#layout/fragment_gender" />
<Button
android:id="#+id/profile_progress_bar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/colorPrimary"
android:text="BUTTON TEXT"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
and below is the layout of the fragment
<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="wrap_content"
tools:context="com.example.fragments.registration.GenderFragment">
<ImageView
android:id="#+id/welcome_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:paddingTop="#dimen/xlarge_top_margin"
android:src="#drawable/bienvenido" />
<TextView
android:id="#+id/gender_explanation"
style="#style/HeaderTitleWhite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/welcome_note"
android:layout_centerHorizontal="true"
android:text="WELCOME TO THE APP"
android:textSize="#dimen/header_title_text_view_xtra_big_size" />
<LinearLayout
android:id="#+id/gender_avatar_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/gender_explanation"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/medium_top_margin"
android:orientation="vertical">
<ImageView
android:id="#+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/woman"
android:scaleType="centerInside" />
<ImageView
android:id="#+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/man"
android:scaleType="centerInside" />
</LinearLayout>
<Button
android:id="#+id/next"
style="#style/AppButtonMedium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/gender_explanation"
android:layout_alignLeft="#+id/gender_explanation"
android:layout_alignRight="#+id/gender_explanation"
android:layout_alignStart="#+id/gender_explanation"
android:layout_below="#+id/gender_avatar_holder"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/large_top_margin"
android:text="NEXT"
android:textStyle="normal|bold" />
</RelativeLayout>
below is a screenshot of how it looks
Your frangment content is too big, so you should user ScrollView inside your layout, like this.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.example.fragments.registration.GenderFragment">
<ImageView
android:id="#+id/welcome_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:paddingTop="#dimen/xlarge_top_margin"
android:src="#drawable/bienvenido" />
<TextView
android:id="#+id/gender_explanation"
style="#style/HeaderTitleWhite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/welcome_note"
android:layout_centerHorizontal="true"
android:text="WELCOME TO THE APP"
android:textSize="#dimen/header_title_text_view_xtra_big_size" />
<LinearLayout
android:id="#+id/gender_avatar_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/gender_explanation"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/medium_top_margin"
android:orientation="vertical">
<ImageView
android:id="#+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="#drawable/woman" />
<ImageView
android:id="#+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="#drawable/man" />
</LinearLayout>
<Button
android:id="#+id/next"
style="#style/AppButtonMedium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/gender_explanation"
android:layout_alignLeft="#+id/gender_explanation"
android:layout_alignRight="#+id/gender_explanation"
android:layout_alignStart="#+id/gender_explanation"
android:layout_below="#+id/gender_avatar_holder"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/large_top_margin"
android:text="NEXT"
android:textStyle="normal|bold" />
</RelativeLayout>

Android ScrollView not scrolling at all

Below is my XML code, I want the whole view to scroll, but it's just not working, please help, with what's wrong;
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/app_icon"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"/>
<TextView
android:id="#+id/textView_app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_gravity="center"/>
<TextView
android:id="#+id/textView_content"
android:layout_width="match_parent"
android:layout_marginTop="15dp"
android:layout_height="386dp"
android:gravity="center"></TextView>
</LinearLayout>
</ScrollView>
I've tried using,
android:fillViewport="true"
but of no help.
A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects.
So here you have to take LinearLayout or RelativeLayout and then you have to put different hierarchy of component.
Android : buttons not visible in scrollview
here i have given answer of Some problem so you can follow this for solve your problem with clearing your concept.
Try like this ,Scrolling will work till End
<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">
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/app_icon"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"/>
<TextView
android:id="#+id/textView_app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_gravity="center"/>
<TextView
android:id="#+id/textView_content"
android:layout_width="match_parent"
android:layout_marginTop="15dp"
android:layout_height="386dp"
android:gravity="center"/>
</LinearLayout>
</ScrollView>
</Relativelayout>
If ScrollView fits to your device screen it would not be scrollable, so make sure content inside ScrollView takes space larger than your screen size.
systematix Try this,here you getting scroll.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/textView_app_version1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="hello" />
<TextView
android:id="#+id/textView_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:gravity="center"
android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/textView_app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="hello" />
<TextView
android:id="#+id/textView_content1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:gravity="center"
android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/textView_app_version2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="hello" />
<TextView
android:id="#+id/textView_content3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:gravity="center"
android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/textView_app_version4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="hello" />
<TextView
android:id="#+id/textView_content4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:gravity="center"
android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>
</LinearLayout>

ScrollView with sub RelativeLayout does not scroll

I have a ScrollView with 1 RelativeLayout which has 3 sub RelativeLayouts:
I set top RelativeLayout to alignParentTop="true",
The bottom RelativeLayout to alignParentBottom="true".
The middle layout to
android:layout_below="#id/topLayout"
android:layout_above="#+id/bottomLayout"
Problem: Scrollview does not scroll when screen is small, instead topLayout stays at top and bottomLayout stays at the bottom. The middle layout gets small and (even lost) as like below:
Desired: I want topLayout stay at top and bottomLayout stay at bottom. But when there is no space there must be scroll so they middle layout must not get lost.
Code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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="#color/white"
tools:context="com.jemshit.itu.fragments.TakeAttendanceFragment"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:paddingBottom="#dimen/halfClassic"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"
android:paddingTop="#dimen/halfClassic">
<RelativeLayout
android:id="#+id/layoutWeekChoice"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="0dp"
android:background="#color/white"
android:layout_alignParentTop="true">
<Spinner
android:id="#+id/spinnerWeekChoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/buttonSetDate"
android:layout_toStartOf="#+id/buttonSetDate"
/>
<Button
android:id="#+id/buttonSetDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:maxWidth="150dp"
android:textSize="16sp"
android:text="Set Date"
android:gravity="center"
android:textColor="#color/white"
android:textAllCaps="false"
android:background="#drawable/button_background"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"
android:layout_alignBottom="#+id/spinnerWeekChoice"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/layoutCardRead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:gravity="center"
android:layout_marginTop="32dp"
android:layout_below="#id/layoutWeekChoice"
android:layout_above="#+id/layoutShowAttendance"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageCard"
android:src="#drawable/std_card"
android:layout_alignParentTop="true"
android:layout_marginBottom="16dp"
android:layout_centerHorizontal="true"/>
<TextView
android:id="#+id/textWarningCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Checking..."
android:textColor="#color/black"
android:textSize="14sp"
android:layout_below="#+id/imageCard"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/layoutShowAttendance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/halfClassic"
android:background="#color/white"
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/textAttended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attended: "
android:textColor="#color/black"
android:layout_alignParentTop="true"
android:textSize="16sp"/>
<TextView
android:id="#+id/textNotAttended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not Attended: "
android:textColor="#color/black"
android:textSize="16sp"
android:layout_marginBottom="32dp"
android:layout_below="#+id/textAttended"/>
<Button
android:id="#+id/buttonManualAttendance"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:text="Manual Attendance"
android:gravity="center"
android:textAllCaps="false"
android:textSize="16sp"
android:textColor="#color/white"
android:background="#drawable/button_background"
android:minHeight="50dp"
android:layout_below="#id/textNotAttended"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
Note: I do not want to use LinearLayout with weight="1" which will make my 3 layouts same height
EDIT: now ScollView scrolls with new code below but my bottom TextViews get lost:
Code Updated:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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="#color/white"
tools:context="com.jemshit.itu.fragments.TakeAttendanceFragment"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:paddingBottom="#dimen/halfClassic"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"
android:paddingTop="#dimen/halfClassic">
<RelativeLayout
android:id="#+id/layoutWeekChoice"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="0dp"
android:background="#color/white"
android:layout_alignParentTop="true">
<Spinner
android:id="#+id/spinnerWeekChoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/buttonSetDate"
android:layout_toStartOf="#+id/buttonSetDate"
/>
<Button
android:id="#+id/buttonSetDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:maxWidth="150dp"
android:textSize="16sp"
android:text="Set Date"
android:gravity="center"
android:textColor="#color/white"
android:textAllCaps="false"
android:background="#drawable/button_background"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"
android:layout_alignBottom="#+id/spinnerWeekChoice"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/layoutCardRead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:gravity="center"
android:layout_marginTop="32dp"
android:layout_below="#id/layoutWeekChoice"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageCard"
android:src="#drawable/std_card"
android:layout_alignParentTop="true"
android:layout_marginBottom="16dp"
android:layout_centerHorizontal="true"/>
<TextView
android:id="#+id/textWarningCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Checking..."
android:textColor="#color/black"
android:textSize="14sp"
android:layout_below="#+id/imageCard"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/layoutShowAttendance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/halfClassic"
android:background="#color/white"
android:layout_below="#id/layoutCardRead"
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/textAttended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attended: "
android:textColor="#color/black"
android:layout_above="#+id/textNotAttended"
android:textSize="16sp"/>
<TextView
android:id="#+id/textNotAttended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not Attended: "
android:textColor="#color/black"
android:textSize="16sp"
android:layout_marginBottom="32dp"
android:layout_above="#+id/buttonManualAttendance" />
<Button
android:id="#+id/buttonManualAttendance"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:text="Manual Attendance"
android:gravity="center"
android:textAllCaps="false"
android:textSize="16sp"
android:textColor="#color/white"
android:background="#drawable/button_background"
android:minHeight="50dp"
android:layout_alignParentBottom="true"
android:paddingLeft="#dimen/halfClassic"
android:paddingRight="#dimen/halfClassic"/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
Set your parents RelativeLayout height to wrap_content. Match_parent needs only ScrollView, everything inside it can spend all the space it needs.
From your 2nd relative layout,that is layoutcard remove android:layout_above="#+id/layoutShowAttendance"
and from layoutShowAttendance remove
android:layout_alignParentBottom="true"
and add android:layout_below="#+id/layoutCardRead" to layoutShowAttendance
It will work.

Categories

Resources