Android Studio:FloatingActionButton wont disappear (edited) - java

I'm new to android so excuse me if I it is too obvious.
My first problem is with the FloatingActionButton. I basically only need on FloatingActionButton wich is to save the search, but there is another one that appears only when I run the app and not in the design view(nor text view).. where did that come from and how can I remove it ??
The XML file
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:layout_marginTop="#dimen/fab_margin_top"
android:src="#drawable/ic_favorite_24dp"
android:contentDescription="#string/save_description"
android:layout_alignParentRight="true"
android:layout_alignParentStart="false"
android:layout_alignTop="#+id/tagTextInputLayout" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/URLTextInputLayout"
android:layout_below="#id/view"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:hint="#string/url_prompt"
android:singleLine="true"
android:layout_below="#+id/view"
android:layout_toRightOf="#+id/URLTextInputLayout"
android:layout_toEndOf="#+id/URLTextInputLayout" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tagTextInputLayout"
android:layout_below="#id/URLTextInputLayout">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/tag_prompt"
android:imeOptions="actionDone" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/tagTextInputLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/tagged_links"
android:id="#+id/textView"
android:gravity="center_horizontal"
android:textStyle="bold"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="#+id/recyclerView"
android:layout_weight="1"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin" />
</LinearLayout>

Related

Android: How to get the Calendar in YEAR/MONTH/DATE Spinners

In my Android app, I am trying to get the birthday of the user. Below is my XML document .
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/colorPurple"
app:popupTheme="#style/AppTheme.PopupOverlay"
style="#style/MyDrawerArrowToggle"
android:layout_marginTop="#dimen/toolbar_layout_top_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="30dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="#+id/signUp_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/back_arrow_white" />
</LinearLayout>
<LinearLayout
android:layout_width="220dp"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20dp"
android:text="#string/birthday"
android:textColor="#color/colorWhite"
android:gravity="center|left"
android:paddingLeft="20dp"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18dp"
android:textStyle="bold"
android:text="#string/what_is_your_birthday"
android:gravity="center"
android:layout_marginTop="60dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="30dp">
<DatePicker
android:layout_width="match_parent"
android:layout_height="150dp"
android:datePickerMode="spinner"
android:id="#+id/date_picker"/>
<!--<com.aigestudio.wheelpicker.widgets.WheelDayPicker-->
<!--android:layout_width="50dp"-->
<!--android:layout_height="match_parent" />-->
<!--<com.aigestudio.wheelpicker.widgets.WheelMonthPicker-->
<!--android:layout_width="50dp"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_marginLeft="20dp"/>-->
<!--<com.aigestudio.wheelpicker.widgets.WheelYearPicker-->
<!--android:layout_width="50dp"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_marginLeft="20dp"/>-->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#color/colorPurple"
android:layout_marginTop="40dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:id="#+id/signup_birthday_next_button_layout">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text = "#string/next_text"
android:textColor="#color/colorWhite"
android:textSize="14dp"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
This gives me the below UI
But I am looking for the below
How can I get the second UI?
Please add this xml file it may be help full to solve your problem.
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:gravity="center"
android:id="#+id/btnNotification"
android:text="What is your birthday"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<DatePicker
android:id="#+id/spinnerDatePicker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:datePickerMode="spinner"
android:descendantFocusability="blocksDescendants"
android:focusable="true"
android:spinnersShown="true" />
<Button
android:text="next"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
You can use SpinnerDatePicker open source library it has UI like below
As it is open source you can change if you need.

Why is android studio reporting URL is not registered?

enter image description here https://docs.google.com/document/d/1_ag-aMsJn408Yef_V0TbVC0GvRIbbuRRPd0uRgsNoM4/edit?usp=sharing
It's in red. I tried to solve it but I still can't resolve the error. :( I already found some similar questions around here but nothing helped me to solve this issue. I hope someone has an idea... ^.^
A valid XML file has only one root node.
Now It included LinearLayout and RelativeLayout.
You must put RelativeLayout and LinearLayout in a reasonable place.
You can do like this,but you need to change the location.
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="sg.edu.tp.uxidcomt.LoginActivity">
<!-- Login progress -->
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone"/>
<ScrollView
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/action_sign_in"
android:textStyle="bold"/>
<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.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:id="#+id/layoutDots"
android:layout_width="match_parent"
android:layout_height="15dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="200dp"
android:gravity="center"
android:orientation="horizontal"></LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#id/layoutDots"
android:alpha=".5"
android:background="#android:color/white"/>
<Button
android:id="#+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#null"
android:next="NEXT"
android:textColor="#android:color/white"/>
<Button
android:id="#+id/btn_skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#null"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:text="SKIP"
android:textColor="#android:color/white"
tools:context=".LoginActivity"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>

scrollview not scrolling android

The ScrollView item is not doing what it should: I canĀ“t scroll.
The code below is a part from a fragment, with splitted screen (thats why I use weight=1). The content of the RelativeLayout is added via code dynamically. The content appears correctly, it is more that could fit onto the screen, so it should be possible to scroll.
I tried out several things:
changing RelativesLayout-height to wrap-content
adding fillViewport="true" to the ScrollView
scrollview not as root element
THE LAYOUT FILE OF THE FRAGMENT
<LinearLayout
android:id="#+id/schichten"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="tuerk.fabian.polarfuchs.AllgemeineInfosFragment">
<ScrollView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:fillViewport="true" >
<RelativeLayout android:id="#+id/schichten_upper_half"
android:isScrollContainer="true"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"/>
</ScrollView>
THE LAYOUT FILE OF THE CONTENT THAT IS DYNAMICALLY ADDED TO THE FRAGMENT (INTO #+id/schichten_upper_half)
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true">
<TextView
android:id="#+id/schichten_ansicht_haerte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FA"
android:textSize="20sp"
android:paddingRight="10sp"
android:layout_centerVertical="true"/>
<TextView
android:id="#+id/schichten_ansicht_von_height"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10 cm"
android:layout_toRightOf="#+id/schichten_ansicht_haerte"/>
<TextView
android:id="#+id/schichten_ansicht_bis_height"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10 cm"
android:layout_below="#id/schichten_ansicht_von_height"
android:layout_toRightOf="#+id/schichten_ansicht_haerte"/>
<TextView
android:id="#+id/schichten_ansicht_naesse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:textSize="20sp"
android:paddingLeft="10sp"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/schichten_ansicht_bis_height"/>
<ImageView
android:id="#+id/schichten_ansicht_1st_grain_form"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/df"
android:paddingLeft="10sp"
android:layout_toRightOf="#id/schichten_ansicht_naesse"/>
<ImageView
android:id="#+id/schichten_ansicht_2nd_grain_form"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/df"
android:layout_toRightOf="#id/schichten_ansicht_1st_grain_form"/>
<TextView
android:id="#+id/schichten_ansicht_durchmesser_von"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.1 "
android:layout_centerVertical="true"
android:paddingLeft="10sp"
android:layout_toRightOf="#+id/schichten_ansicht_2nd_grain_form"/>
<TextView
android:id="#+id/schichten_ansicht_durchmesser_bis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="- 0.3 mm"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/schichten_ansicht_durchmesser_von"/>
</RelativeLayout>
THE LAYOUT FILE OF THE ACITIVITY
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_dialog_email" />

android view layout. make view fill space between views

I am trying to create a layout with basically a head, body, and footer. The ViewPager I am using is filling the space behind the footer content though. How can I make it not do this, and cutoff at the start of the footer content?
<?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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.janedoe.anothertabexample.MainActivity"
tools:showIn="#layout/activity_main">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#id/tabLayout"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp">
<TextView
android:id="#+id/time"
android:layout_width="100dp"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="00:00:00"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/mileage"
android:layout_width="100dp"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:text="0.0 mi"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/time"
android:text="Start" />
<Button
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#id/mileage"
android:text="Stop" />
</RelativeLayout>
</RelativeLayout>
I don't want the color(which is just the content) to run past the Buttons and TextViews on the bottom. I've tried the layout_gravity method as well as setting the viewpager to layout_above and layout_blow but neither appear to work. How can I achieve this?
You view pager will consume all space available.
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#id/tabLayout"/>
I would try switching to a LinearLayout and use the "android:layout_weight" property to force the ViewPager to only use available space.
your RelativeLayout should have android:layout_alignParentBottom="true".
<RelativeLayout android:id="#+id/relativeFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="5dp">
Remove android:layout_alignParentBottom="true" from all its child.
and your viewpager should look like below
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/relativeFooter"
android:layout_below="#id/tabLayout"/>
Finally your whole layout should be like below :
<?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"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/relativeFooter"
android:layout_below="#id/tabLayout"/>
<RelativeLayout android:id="#+id/relativeFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="5dp">
<TextView
android:id="#+id/time"
android:layout_width="100dp"
android:layout_height="55dp"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="00:00:00"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/mileage"
android:layout_width="100dp"
android:layout_height="55dp"
android:layout_alignParentRight="true"
android:gravity="center"
android:text="0.0 mi"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/time"
android:text="Start" />
<Button
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#id/mileage"
android:text="Stop" />
</RelativeLayout>

Android : buttons not visible in scrollview

I am making an android app to enter user information, for that I have two button and number picker, my button are customize and are not showing in either preview in android studio neither in emulator
Here is my code
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.app.tarun.dc2.Fragments.AddressFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical"
>
<!--Layout for Buttons-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
>
<com.app.tarun.dc2.CustomViews.SquareLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="25dp"
android:layout_weight="1">
<ImageButton
android:src="#drawable/ic_add"
android:id="#+id/medicineEditAddButton"
android:scaleType="fitCenter"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/green_button_style"/>
</com.app.tarun.dc2.CustomViews.SquareLayout>
<NumberPicker
android:layout_width="0dp"
android:id="#+id/medicineEditNumberPicker"
android:layout_height="wrap_content"
android:layout_weight="1">
</NumberPicker>
<com.app.tarun.dc2.CustomViews.SquareLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="25dp"
android:layout_weight="1">
<ImageButton
android:src="#drawable/ic_continue"
android:id="#+id/medicineEditContinueButton"
android:scaleType="fitCenter"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/yellow_button_style"/>
</com.app.tarun.dc2.CustomViews.SquareLayout>
</LinearLayout>
<!--Horizontal Linear Layout for EDITTEXT-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="First Name"
android:inputType="text"
android:layout_marginTop="25dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Last Name"
android:inputType="text"
android:layout_marginTop="25dp"/>
</LinearLayout>
<!--Horizontal Linear Layout for EDITTEXT end here(First name and last name-->
</LinearLayout></ScrollView>
Change your custom layout's width from 0dp to wrap content/match_parent depending on your need. I think that may solve your problem. I have your edited layout in below.
<com.app.tarun.dc2.CustomViews.SquareLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="25dp"
android:layout_weight="1">
<ImageButton
android:src="#drawable/ic_add"
android:id="#+id/medicineEditAddButton"
android:scaleType="fitCenter"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/green_button_style"/>
</com.app.tarun.dc2.CustomViews.SquareLayout>
<NumberPicker
android:layout_width="wrap_content"
android:id="#+id/medicineEditNumberPicker"
android:layout_height="wrap_content"
android:layout_weight="1">
</NumberPicker>
<com.app.tarun.dc2.CustomViews.SquareLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="25dp"
android:layout_weight="1">
<ImageButton
android:src="#drawable/ic_continue"
android:id="#+id/medicineEditContinueButton"
android:scaleType="fitCenter"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/yellow_button_style"/>
</com.app.tarun.dc2.CustomViews.SquareLayout>
Try including your scroll view in a layout. Here is how i have achieved it for a project of mine:
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.com.atr.LoginActivity" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="#+id/txthello"></TextView>
<EditText
android:id="#+id/txtApp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txthello"
android:layout_marginTop="18dp"
android:hint="Enter Application Code"/>
<EditText
android:id="#+id/txtModuleId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtApp"
android:layout_marginTop="18dp"
android:hint="Enter Module Id"/>
<EditText
android:id="#+id/txtModuleCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtModuleId"
android:layout_marginTop="18dp"
android:hint="Enter Module Code"/>
<EditText
android:id="#+id/txtModuleType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtModuleCode"
android:layout_marginTop="18dp"
android:hint="Enter Module Type"/>
<EditText
android:id="#+id/txtSubModuleId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtModuleType"
android:layout_marginTop="18dp"
android:hint="Enter Sub Module Id"/>
<EditText
android:id="#+id/txtSubModuleCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtSubModuleId"
android:layout_marginTop="18dp"
android:hint="Enter Sub Module Code"/>
<EditText
android:id="#+id/txtUserId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtSubModuleCode"
android:layout_marginTop="18dp"
android:hint="Enter User Id"/>
<EditText
android:id="#+id/txtDateFrom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtUserId"
android:layout_marginTop="18dp"
android:hint="From Date (mmm-dd-yyyy)"/>
<EditText
android:id="#+id/txtDateTo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtDateFrom"
android:layout_marginTop="18dp"
android:hint="To Date (mmm-dd-yyyy)"/>
<Button
android:id="#+id/btnCallService"
android:layout_width="80dp"
android:layout_height="45dp"
android:layout_below="#+id/txtDateTo"
android:layout_toRightOf="#+id/txtDateTo"
android:layout_marginTop="18dp"
android:layout_alignParentLeft="true"
android:text="Send"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Just to give you a basic idea :)
Add a android:weightSum="[any int]" on your first LinearLayout
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.
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.app.tarun.dc2.Fragments.AddressFragment">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical"
>
<!--Layout for Buttons-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
>
<com.app.tarun.dc2.CustomViews.SquareLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="25dp"
android:layout_weight="1">
<ImageButton
android:src="#drawable/ic_add"
android:id="#+id/medicineEditAddButton"
android:scaleType="fitCenter"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/green_button_style"/>
</com.app.tarun.dc2.CustomViews.SquareLayout>
<NumberPicker
android:layout_width="0dp"
android:id="#+id/medicineEditNumberPicker"
android:layout_height="wrap_content"
android:layout_weight="1">
</NumberPicker>
<com.app.tarun.dc2.CustomViews.SquareLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="25dp"
android:layout_weight="1">
<ImageButton
android:src="#drawable/ic_continue"
android:id="#+id/medicineEditContinueButton"
android:scaleType="fitCenter"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/yellow_button_style"/>
</com.app.tarun.dc2.CustomViews.SquareLayout>
</LinearLayout>
<!--Horizontal Linear Layout for EDITTEXT-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="First Name"
android:inputType="text"
android:layout_marginTop="25dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Last Name"
android:inputType="text"
android:layout_marginTop="25dp"/>
</LinearLayout>
<!--Horizontal Linear Layout for EDITTEXT end here(First name and last name-->
</LinearLayout>
</LinearLayout></ScrollView>
Hope so this code is work for you.
And you can also visit this ScrollView

Categories