My Fragment layout is overlapping Activity layout - android

I have an Activity with two buttons. Button click opens a new Fragment. But the Fragment view is overlapping my Activity view.
I have tried giving background to my fragment but it is not working for me
Here is activity xml code
<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"
android:background="#E6E6E6"
tools:context=".TourAdmin">
<TextView
android:id="#+id/tour_admin_tour_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Tournament Name"
android:textSize="30dp" />
<Button
android:id="#+id/tour_admin_schedule"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="#+id/tour_admin_tour_name"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:background="#color/colorPrimary"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Schedule Match"
android:textColor="#fff" />
<Button
android:id="#+id/tour_admin_show_for_score"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="#+id/tour_admin_schedule"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:background="#color/colorPrimary"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Score Match"
android:textColor="#fff" />
<FrameLayout
android:id="#+id/admin_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Here is fragment 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:layout_margin="2dp"
android:background="#android:color/holo_red_dark"
tools:context=".TourScheduleMatch">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Spinner
android:id="#+id/tour_team1_select_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:paddingLeft="6dp"
android:paddingRight="6dp" />
<Spinner
android:id="#+id/tour_team2_select_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tour_team1_select_spinner"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
/>
<Spinner
android:id="#+id/tour_sched_half_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tour_team2_select_spinner"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:entries="#array/match_time"/>
<Spinner
android:id="#+id/tour_sched_nop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tour_sched_half_time"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:entries="#array/tournament_nop"/>
<EditText
android:id="#+id/tour_cityNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_marginTop="24dp"
android:layout_marginRight="24dp"
android:layout_weight="0"
android:hint="City"
android:inputType="text"
android:padding="8dp"
android:layout_below="#id/tour_sched_nop"/>
<EditText
android:id="#+id/tour_groundNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_marginTop="24dp"
android:layout_marginRight="24dp"
android:layout_weight="0"
android:hint="Ground"
android:inputType="text"
android:padding="8dp"
android:layout_below="#id/tour_cityNameEditText"/>
<LinearLayout
android:id="#+id/match_date_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="#id/tour_groundNameEditText"
android:layout_centerHorizontal="true">
<Button
android:id="#+id/tour_match_date_bn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:background="#color/colorPrimary"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:text="Match Date"
android:textColor="#fff" />
<TextView
android:id="#+id/tour_match_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="85dp"
android:layout_marginTop="28dp"
android:text="Match Date"
android:textColor="#000"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/match_time_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/match_date_layout"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp">
<Button
android:id="#+id/tour_match_time_bn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:background="#color/colorPrimary"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:text="Match Time"
android:textColor="#fff" />
<TextView
android:id="#+id/tour_match_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="85dp"
android:layout_marginTop="28dp"
android:text="Match Time"
android:textColor="#000"
android:textSize="20dp" />
</LinearLayout>
<Button
android:id="#+id/tour_schedule_schedule_bn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/match_time_layout"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:background="#color/colorPrimary"
android:text="Create"
android:textColor="#fff" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>

I hope you are using a ConstraintLayout. To make the elements align one after another, use a LinearLayout or FrameLayout.

Using RelativeLayout here is wrong option. You should use LinearLayout instead. Place your FrameLayout as first view in your activity layout and change its visibility from gone to visible when needed.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E6E6E6"
android:orientation="vertical">
<FrameLayout
android:id="#+id/admin_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
<TextView
android:id="#+id/tour_admin_tour_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="60dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Tournament Name"
android:textSize="30dp" />
<Button
android:id="#+id/tour_admin_schedule"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_gravity="center_horizontal"
android:background="#color/colorPrimary"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Schedule Match"
android:textColor="#fff" />
<Button
android:id="#+id/tour_admin_show_for_score"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="#+id/tour_admin_schedule"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
android:background="#color/colorPrimary"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Score Match"
android:textColor="#fff" />
</LinearLayout>
Another option is using ConstraintLayout but it is harder to use than LinearLayout.

Related

Scroll View doesn't work in Frame Layout - Android XML

I'm using fragments to recreate a design, so basically my design consists of four buttons which are present in a Relative Layout and the remaining empty space of the activity is used as a fragment.
So everything works fine until the content in the fragment goes beyond the screen and it is not visible anymore. So I want to implement a ScrollView, so the user can scroll to see all the content, but unfortunately that doesn't work. I have been looking for solution all day but nothing helped.
Here is the image for reference.
Every suggestion is appreciated! Thank you.
Here is the code;
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".Fragment_1">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text_1_frame_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginEnd="10dp"
android:fontFamily="#font/alata"
android:textStyle="bold"
android:text="#string/fragment_1_text_1"
android:textColor="#color/Deloitte"
android:textSize="32sp" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/text_1_frame_1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/rl1_frame_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:background="#drawable/frame_design">
<TextView
android:id="#+id/education_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/open_sans"
android:padding="10dp"
android:text="#string/bachelors_in_engineering_cse"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:fontFamily="#font/open_sans"
android:layout_below="#id/education_1"
android:text="#string/neil_gogte_institute_of_technology_n_2020_2023"
android:textColor="#color/white"
android:textStyle="italic"
android:textSize="16sp"
android:paddingBottom="10dp"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl1_frame_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rl1_frame_1"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:background="#drawable/frame_design">
<TextView
android:id="#+id/education_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/open_sans"
android:padding="10dp"
android:text="#string/diploma_in_computer_science"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:fontFamily="#font/open_sans"
android:layout_below="#id/education_2"
android:text="#string/government_institute_of_electronics_n_2016_2019"
android:textColor="#color/white"
android:textStyle="italic"
android:textSize="16sp"
android:paddingBottom="10dp"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl1_frame_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rl1_frame_2"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:background="#drawable/frame_design">
<TextView
android:id="#+id/education_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/open_sans"
android:padding="10dp"
android:text="#string/ts_ssc"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:fontFamily="#font/open_sans"
android:layout_below="#id/education_3"
android:text="#string/bhashyam_high_school_n_2015_2016"
android:textColor="#color/white"
android:textStyle="italic"
android:textSize="16sp"
android:paddingBottom="10dp"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/certification_rl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_below="#id/rl1_frame_3"
android:background="#drawable/frame_design">
<ImageView
android:id="#+id/certification"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:contentDescription="#string/certificate_icon"
android:layout_centerHorizontal="true"
android:src="#drawable/certification" />
<TextView
android:id="#+id/certification_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/certification"
android:layout_centerHorizontal="true"
android:fontFamily="#font/open_sans"
android:padding="10dp"
android:text="#string/android_basics_nanodegree_by_google"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/certification_1"
android:fontFamily="#font/open_sans"
android:paddingBottom="10dp"
android:layout_centerHorizontal="true"
android:text="Certified on July,2019 "
android:textColor="#color/white"
android:textSize="16sp"
android:textStyle="italic"
tools:ignore="HardcodedText" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/certification_rl_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_below="#id/rl1_frame_3"
android:background="#drawable/frame_design">
<ImageView
android:id="#+id/certification_img"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:contentDescription="#string/certificate_icon"
android:layout_centerHorizontal="true"
android:src="#drawable/certification" />
<TextView
android:id="#+id/certification_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/certification_img"
android:layout_centerHorizontal="true"
android:fontFamily="#font/open_sans"
android:padding="10dp"
android:text="#string/android_basics_nanodegree_by_google"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/certification_2"
android:fontFamily="#font/open_sans"
android:paddingBottom="10dp"
android:layout_centerHorizontal="true"
android:text="Certified on July,2019 "
android:textColor="#color/white"
android:textSize="16sp"
android:textStyle="italic"
tools:ignore="HardcodedText" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
Here is main activity for the fragments!
<androidx.constraintlayout.widget.ConstraintLayout 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=".More_Info">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:orientation="horizontal"
android:layout_marginTop="15dp"
android:id="#+id/more_cv_ll">
<RelativeLayout
android:layout_weight="1"
android:id="#+id/rl_1"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp"
android:layout_width="100dp"
android:layout_marginBottom="15dp"
android:background="#drawable/bg_buttons"
android:layout_height="100dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/education"
android:layout_centerInParent="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:id="#+id/rl_2"
android:layout_marginStart="15dp"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="15dp"
android:background="#drawable/bg_buttons"
android:layout_marginBottom="15dp"
android:layout_toRightOf="#id/rl_1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/skills" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_3"
android:layout_weight="1"
android:layout_marginStart="15dp"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:background="#drawable/bg_buttons"
android:layout_toRightOf="#id/rl_2">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/work_exp"
android:layout_centerInParent="true"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_4"
android:layout_weight="1"
android:layout_marginEnd="15dp"
android:layout_marginStart="15dp"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="15dp"
android:background="#drawable/bg_buttons"
android:layout_marginTop="15dp"
android:layout_toRightOf="#id/rl_3">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/contact"
android:layout_centerInParent="true"/>
</RelativeLayout>
</LinearLayout>
<FrameLayout
android:id="#+id/cv_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/more_cv_ll" />
</androidx.constraintlayout.widget.ConstraintLayout>
ScrollView must have only 1 child. Currently you have a Linear and a Relative Layout inside it. Make sure to have only 1 layout group inside scrollview eg LinearLayout and then add your views to that LinearLayout

Background ImageView is not Shown in API level 16 though working good in API 19

I am not able to find out the exact issue that why the image(background) is not visible in API level 16 but it is showing good in API level 19. I have worked simply as i have done previously but , this time the background is not shown(of WaterMark in ImageView).
I am not able to find out what is exact issue . So i need help.I have done every thing as suggested in the stack Android device is not showing the background image but it is not going good in my case.
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"
android:orientation="vertical">
<ScrollView
android:id="#+id/scrollLogin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/rlGetInTouch"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#304EA2">
<RelativeLayout
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/header_bg2">
<ImageView
android:id="#+id/brand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/nbl_logo4" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#304EA2">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_marginBottom="35dp"
android:layout_marginTop="-60dp"
android:color="#android:color/transparent"
android:src="#drawable/logowatermark" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/edit_text_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="35dp"
android:paddingRight="35dp">
<******.CustomFontLoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:text=" Please login to proceed"
android:textColor="#color/white"
android:textSize="12sp"
android:textStyle="normal" />
<******.CustomFontEditText
android:id="#+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:background="#drawable/edit_text_border"
android:drawablePadding="8dp"
android:gravity="center"
android:hint="Mobile Number"
android:inputType="number"
android:maxLength="#integer/mobile_length"
android:padding="13dp"
android:textCursorDrawable="#drawable/color_cursor"
android:textSize="12dp"
android:textStyle="bold" />
<******.CustomFontEditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="12dp"
android:layout_toLeftOf="#+id/passwordVisibilityBtn"
android:background="#drawable/edit_text_border"
android:drawablePadding="8dp"
android:gravity="center"
android:hint="Password"
android:inputType="textPassword"
android:maxLength="#integer/password_length"
android:padding="13dp"
android:textCursorDrawable="#drawable/color_cursor"
android:textSize="12dp"
android:textStyle="bold" />
<******.CustomFontCheckBox
android:id="#+id/chkSaveUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:button="#drawable/custom_checkbox"
android:drawablePadding="5dp"
android:gravity="center"
android:text=" Remember Mobile No."
android:textColor="#color/white"
android:textSize="12sp"
android:textStyle="normal" />
<LinearLayout
android:id="#+id/loginLl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#drawable/login_button_shadow"
android:orientation="vertical">
<******.CustomFontLoginTextView
android:id="#+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/login_button_new1"
android:clickable="true"
android:gravity="center"
android:padding="13dp"
android:text="Login"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="14sp" />
<******.CustomFontLoginTextView
android:id="#+id/action_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/login_button_new1"
android:clickable="true"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="10dp"
android:text="Switch To SMS"
android:textColor="#color/white"
android:textSize="12sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<******.CustomFontLoginTextView
android:id="#+id/resetDeviceId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:alpha="0.7"
android:drawableLeft="#drawable/icon_reset_20"
android:drawablePadding="3dp"
android:gravity="center"
android:text="#string/reset_device_id_text"
android:textColor="#color/white"
android:textSize="12sp" />
<******.CustomFontLoginTextView
android:id="#+id/action_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:alpha="0.7"
android:drawableLeft="#drawable/icon_info_20"
android:drawablePadding="3dp"
android:gravity="center"
android:text="#string/info"
android:textColor="#color/white"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<!-- Promo -->
<LinearLayout
android:id="#+id/llPromotions"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/promo_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/llBranches"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rlLogin"
android:layout_gravity="center"
android:background="#304EA2"
android:gravity="center"
android:orientation="horizontal"
android:padding="15dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:onClick="showATMs"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:padding="2dp"
android:src="#drawable/icon_atm_50_6" />
<******.CustomFontLoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:text="ATM"
android:textColor="#FFFFFF"
android:textSize="12sp" />
<******.CustomFontLoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="3dp"
android:text="Locate nearest Atm Machines"
android:textColor="#FFFFFF"
android:textSize="8sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:onClick="showBranches"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="2dp"
android:src="#drawable/ic_branches_50_6" />
<******.CustomFontLoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="8dp"
android:text="BRANCHES"
android:textColor="#FFFFFF"
android:textSize="12sp" />
<******.CustomFontLoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="3dp"
android:text="Locate nearest bank branches"
android:textColor="#FFFFFF"
android:textSize="8sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:onClick="showRates"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="2dp"
android:src="#drawable/ic_rates_50_6" />
<******.CustomFontLoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:text="RATES"
android:textColor="#FFFFFF"
android:textSize="12sp" />
<******.CustomFontLoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="3dp"
android:text="Foreign exchange and stock rates"
android:textColor="#FFFFFF"
android:textSize="8sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/rlProducts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="vertical">
<******.CustomFontLoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="Products"
android:textAllCaps="true"
android:textColor="#color/gray"
android:textSize="14sp" />
<!--Product Container-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!--Product 1-->
<LinearLayout
android:id="#+id/product_content1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="7.5dp"
android:layout_weight="1"
android:orientation="vertical" />
<!--Product 2-->
<LinearLayout
android:id="#+id/product_content2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="7.5dp"
android:layout_marginRight="15dp"
android:layout_weight="1"
android:gravity="end"
android:orientation="vertical" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/rlGetInTouch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#304EA2"
android:orientation="horizontal">
<CustomFontLoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/btnCall"
android:paddingLeft="15dp"
android:singleLine="true"
android:text="Get in touch with us"
android:textColor="#color/white"
android:textSize="16sp"
android:textStyle="normal" />
<!--app:maxTextSize="14sp"
app:minTextSize="#dimen/minFontSize"-->
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/btnMap"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:onClick="showLocation"
android:src="#drawable/ic_action_location_24_4" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/btnEmail"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/btnMap"
android:layout_toStartOf="#+id/btnMap"
android:onClick="openEmail"
android:src="#drawable/ic_action_mail_24_4" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/btnCall"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/btnEmail"
android:layout_toStartOf="#+id/btnEmail"
android:onClick="openCall"
android:src="#drawable/ic_action_call_24_4" />
</RelativeLayout>
</RelativeLayout>
The Image background of watermark is not shown. I have done nothing
new ,same as previous but dont' know that is the exact issue.
Please reduce image size to visible in the lower level device.
I Just Removed marginTop and it worked fine in API level 16
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_marginBottom="35dp"
android:src="#drawable/logowatermark" />
I don't understand that why it worked when i remove the -ve marginTop
in above? .I got solution but don't understand what exactly happened
in adding -ve marginTop and with removing -ve marginTop.

ScrollView inside Fragment Relative layout is not working

I am using fragment to display registration page
I want "OTP" button stick to the bottom, so I used relative layout for that. I am using linear layout for edittext. When i click on edittext, keyboard appeared but when I am trying to scroll the page when keyboard is opened, its not scrolling at all
Someone please Help
Here is my fragment 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="#F4F4F4"
tools:context="values.Registration">
<ScrollView
android:fillViewport="true"
android:isScrollContainer="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F4F4F4"
android:orientation="vertical">
<ImageView
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:background="#mipmap/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="#fff"
android:orientation="horizontal">
<TextView
android:layout_width="130dp"
android:layout_height="58dp"
android:layout_gravity="center"
android:gravity="center_vertical"
android:paddingLeft="15dp"
android:text="Mobile No. /\nमो. नंबर "
android:textSize="17dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="58dp"
android:layout_gravity="center"
android:gravity="center_vertical"
android:hint="Mobile NO."
android:maxLength="10"
android:paddingLeft="15dp"
android:paddingStart="5dp"
android:phoneNumber="true"
android:singleLine="true"
android:textColor="#000"
android:textColorHint="#fff"
android:textSize="17dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:background="#fff"
android:orientation="horizontal">
<TextView
android:id="#+id/textView5"
android:layout_width="130dp"
android:layout_height="58dp"
android:layout_gravity="center"
android:gravity="center_vertical"
android:paddingLeft="15dp"
android:text="Mail Id. /\nइ-मेल "
android:textSize="17dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="58dp"
android:layout_gravity="center"
android:gravity="center_vertical"
android:hint="Mobile NO."
android:paddingLeft="15dp"
android:paddingStart="5dp"
android:singleLine="true"
android:textColor="#000"
android:textColorHint="#fff"
android:textSize="17dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="60dp"
android:layout_marginTop="2dp"
android:background="#fff"
android:orientation="horizontal">
<TextView
android:layout_width="130dp"
android:layout_height="58dp"
android:layout_gravity="center"
android:gravity="center_vertical"
android:paddingLeft="15dp"
android:text="Name /\nनाव"
android:textSize="17dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="58dp"
android:layout_gravity="center"
android:gravity="center_vertical"
android:hint="Mobile NO."
android:paddingLeft="15dp"
android:paddingStart="5dp"
android:singleLine="true"
android:textColor="#000"
android:textColorHint="#fff"
android:textSize="17dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/bt_send_otp"
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/colorPrimary"
android:drawablePadding="-40dp"
android:drawableRight="#drawable/arrow_right"
android:paddingRight="15dp"
android:text="SEND OTP / वो. टि. पी. पाठवा"
android:textColor="#FFF"
android:textSize="16dp" />
</RelativeLayout>
in Manifest:
android:windowSoftInputMode="adjustResize"

Place ImageButton in the center of ImageView

How can I adjust the imageButton in the center of ImageView?
Below are the code I have tried:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.AppCompat"
android:background="#color/darkpurple"
android:minHeight="?attr/actionBarSize">
<Button
android:text="Save"
android:id="#+id/save"
android:background="#color/darkpurple"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:textColor="#fff"
android:layout_height="wrap_content"
android:textSize="12sp" />
</android.support.v7.widget.Toolbar>
<ImageView
android:layout_height="200dp"
android:layout_width="200dp"
android:layout_marginTop="15dp"
android:background="#color/light_gray"
android:layout_below="#+id/toolbar"
android:layout_marginRight="25dp"
android:layout_alignParentRight="true"
android:id="#+id/imageView"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="65dp"
android:background="#drawable/camera"
android:layout_height="55dp"
android:layout_marginRight="5dp"
android:id="#+id/imageButtonOne"
android:paddingTop="100dp"
android:layout_marginTop="67dp"
android:layout_alignTop="#+id/imageView"
android:layout_alignRight="#+id/comments"
android:layout_alignEnd="#+id/comments" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textColor="#color/red"
android:textStyle="bold"
android:id="#+id/Date"
android:textSize="15sp"
android:text="Date"/>
<EditText
android:layout_width="match_parent"
android:id="#+id/date"
android:layout_below="#+id/Date"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:textSize="15sp"
android:hint="Date"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textColor="#color/red"
android:textStyle="bold"
android:id="#+id/Amount"
android:textSize="15sp"
android:text="Amount"
android:layout_below="#+id/date" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/Amount"
android:paddingLeft="20dp"
android:id="#+id/amount"
android:inputType="numberDecimal"
android:textSize="15sp"
android:hint="Amount"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textStyle="bold"
android:id="#+id/Comments"
android:textSize="15sp"
android:text="Comments"
android:layout_below="#+id/amount" />
<EditText
android:layout_width="290dp"
android:layout_height="120dp"
android:paddingBottom="80dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
android:paddingLeft="13dp"
android:id="#+id/comments"
android:textSize="15sp"
android:background="#drawable/roundedcorner_edittext"
android:hint="Comments"
android:layout_below="#+id/Comments"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
My ScreenShot
<FrameLayout android:layout_height="200dp"
android:layout_width="200dp"
android:layout_below="#+id/toolbar"
android:layout_marginRight="25dp"
android:layout_marginTop="15dp"
android:layout_alignParentRight="true">
<ImageView
android:layout_height="200dp"
android:layout_width="200dp"
android:background="#color/light_gray"
android:id="#+id/imageView"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="65dp"
android:background="#drawable/camera"
android:layout_height="55dp"
android:id="#+id/imageButtonOne"
android:layout_gravity = "center"
/>
</FrameLayout>
Check it.
Use code, it works for all screen size(Please replace image with yours):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.AppCompat"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize">
<Button
android:text="Save"
android:id="#+id/save"
android:background="#color/colorPrimary"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:textColor="#fff"
android:layout_height="wrap_content"
android:textSize="12sp" />
</android.support.v7.widget.Toolbar>
<ImageView
android:layout_height="200dp"
android:layout_width="200dp"
android:layout_marginTop="15dp"
android:background="#color/colorPrimary"
android:layout_below="#+id/toolbar"
android:layout_marginRight="25dp"
android:layout_alignParentRight="true"
android:id="#+id/imageView"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="70dp"
android:background="#mipmap/ic_launcher"
android:layout_height="60dp"
android:layout_marginTop="70dp"
android:layout_marginRight="65dp"
android:id="#+id/imageButtonOne"
android:layout_alignTop="#+id/imageView"
android:layout_alignEnd="#+id/imageView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textColor="#color/colorPrimary"
android:textStyle="bold"
android:id="#+id/Date"
android:textSize="15sp"
android:text="Date"/>
<EditText
android:layout_width="match_parent"
android:id="#+id/date"
android:layout_below="#+id/Date"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:textSize="15sp"
android:hint="Date"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textColor="#color/colorPrimary"
android:textStyle="bold"
android:id="#+id/Amount"
android:textSize="15sp"
android:text="Amount"
android:layout_below="#+id/date" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/Amount"
android:paddingLeft="20dp"
android:id="#+id/amount"
android:inputType="numberDecimal"
android:textSize="15sp"
android:hint="Amount"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textStyle="bold"
android:id="#+id/Comments"
android:textSize="15sp"
android:text="Comments"
android:layout_below="#+id/amount" />
<EditText
android:layout_width="290dp"
android:layout_height="120dp"
android:paddingBottom="80dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
android:paddingLeft="13dp"
android:id="#+id/comments"
android:textSize="15sp"
android:background="#mipmap/ic_launcher"
android:hint="Comments"
android:layout_below="#+id/Comments"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
The idea is simple, make changes according to this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="250dp"
android:layout_height="250dp" >
<ImageView
android:id="#+id/base"
android:layout_height="250dp"
android:layout_width="250dp"
android:src="#drawable/home"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<ImageButton
android:id="#+id/center"
android:layout_height="150dp"
android:layout_width="150dp"
android:src="#drawable/home"
android:layout_centerInParent="true"
android:layout_centerVertical="true" />
</RelativeLayout>
</RelativeLayout>
In order to move it to the top right corner, you can specify
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
to the Relative Layout with fixed widths, This places the Layout at the top right corner, then you can add margins to keep at a position where you require.
Hope it helps :)
Past this as it is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.AppCompat"
android:background="#color/darkpurple"
android:minHeight="?attr/actionBarSize">
<Button
android:text="Save"
android:id="#+id/save"
android:background="#color/darkpurple"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:textColor="#fff"
android:layout_height="wrap_content"
android:textSize="12sp" />
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:id="#+id/rlImages"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_below="#+id/toolbar"
android:layout_marginRight="25dp"
android:layout_marginTop="15dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#color/light_gray" />
<Button
android:id="#+id/imageButtonOne"
android:layout_width="65dp"
android:layout_height="55dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/add_tag" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rlImages"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textColor="#color/red"
android:textStyle="bold"
android:id="#+id/Date"
android:textSize="15sp"
android:text="Date"/>
<EditText
android:layout_width="match_parent"
android:id="#+id/date"
android:layout_below="#+id/Date"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:textSize="15sp"
android:hint="Date"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textColor="#color/red"
android:textStyle="bold"
android:id="#+id/Amount"
android:textSize="15sp"
android:text="Amount"
android:layout_below="#+id/date" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/Amount"
android:paddingLeft="20dp"
android:id="#+id/amount"
android:inputType="numberDecimal"
android:textSize="15sp"
android:hint="Amount"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textStyle="bold"
android:id="#+id/Comments"
android:textSize="15sp"
android:text="Comments"
android:layout_below="#+id/amount" />
<EditText
android:layout_width="290dp"
android:layout_height="120dp"
android:paddingBottom="80dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
android:paddingLeft="13dp"
android:id="#+id/comments"
android:textSize="15sp"
android:background="#drawable/roundedcorner_edittext"
android:hint="Comments"
android:layout_below="#+id/Comments"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
You need to use RelativeLayout with the use of
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
You can use FrameLayout with that
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
android:src="#drawable/img" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_gravity="center_horizontal|bottom"
android:padding="12dip"
android:background="#000000"
android:textColor="#ffffffff"
android:text="Button" />
</FrameLayout>

how do i use both scroll view and RecyclerView in one xml layout android?

In my application i am using recycler view and scrollview in one layout. it is not working when i am using both these views. If i remove scroll view only the recycler view is working. Plese any one help me hoe to fix this issue.
my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/r1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
>
<ScrollView
android:id="#+id/sc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1e356a">
<TextView
android:id="#+id/placce_head"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Hyderabad to banglore"
android:textColor="#ffffff"
android:textSize="20dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:id="#+id/seats"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Selected Seats"
android:textColor="#ffffff"
android:textSize="16dp" />
<TextView
android:id="#+id/totalamount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Total Amount"
android:textColor="#ffffff"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:id="#+id/seat_num"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:textColor="#ffffff"
android:textSize="16dp" />
<TextView
android:id="#+id/total_amount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#ffffff"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/boardingpoint_edttxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:background="#null"
android:hint=" Select Boarding Point"
android:textColorHint="#1e365a"
android:textSize="15dp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="7dp"
android:background="#1e365a" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/contact_details"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Contact Details"
android:textColor="#ffffff"
android:textSize="20dp" />
</RelativeLayout>
<EditText
android:id="#+id/contactname_edt_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:background="#null"
android:hint="Contact Name"
android:textColorHint="#1e365a"
android:textSize="15dp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="7dp"
android:background="#1e365a" />
<EditText
android:id="#+id/email_edt_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:background="#null"
android:hint="Email Address"
android:textColorHint="#1e365a"
android:textSize="15dp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="7dp"
android:background="#1e365a" />
<EditText
android:id="#+id/contactnum_edt_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:background="#null"
android:hint="Contact Number"
android:textColorHint="#1e365a"
android:textSize="15dp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="7dp"
android:background="#1e365a" />
<EditText
android:id="#+id/emergency_edt_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:background="#null"
android:hint="Emergency Contact Number"
android:textColorHint="#1e365a"
android:textSize="15dp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="7dp"
android:background="#1e365a" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/passenger_details"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Passenger Details"
android:textColor="#ffffff"
android:textSize="20dp" />
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/view"
android:layout_below="#+id/sc"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<LinearLayout
android:id="#+id/coupon_lay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="8dp"
android:layout_marginTop="12dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="100" >
<EditText
android:id="#+id/entercouponcode_edt"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="50"
android:hint="Enter coupn code"
android:inputType="text" >
<requestFocus />
</EditText>
<Button
android:id="#+id/bt_apply"
style="#style/payment_button_style"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="-5dp"
android:layout_weight="40"
android:gravity="center"
android:text="Apply" />
</LinearLayout>
<Button
android:id="#+id/pay_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:background="#F93249"
android:duplicateParentState="true"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="Proceed to Pay"
android:textColor="#ffffff"
android:textSize="20dp"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
you must know that ,your scrollview property is set as MatchParent ,which means it will fill the content view, so i suggest to set Height a real value such as 100dp, and it will work
You need to dynamically change the height of the recyclerview, depending on how many items you have.
int recyclerheight = height_per_item * adapterData.size();
recyclerView.getLayoutParams().height = recyclerheight;
The scroll view blocks the recyclerview from changing its height set in the xml, that's why you need to do it programically.

Categories

Resources