This question already has answers here:
How to disable RecyclerView scrolling to make the layout listen its ScrollView parent?
(3 answers)
Closed 5 years ago.
I have problem with ScrollView. I'm trying to get it in Relative Layout. I have tried some solutions,but nothing works.I tried setting my relative layout's height to match_parent but it doesn't work also. I can get it to work with linear layout but I don't want to use it for some reason.
MY Xml code:
`
<?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"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100">
<LinearLayout
android:id="#+id/actionbarh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/helpdesk_color"
android:orientation="horizontal"
android:weightSum="100">
<ImageView
android:id="#+id/htoolback"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="03dp"
app:srcCompat="#drawable/ic_back"
android:tint="#FFFFFF"
android:layout_gravity="center"
android:gravity="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="83"
android:textColorHint="#FFFFFF"
android:layout_gravity="center"
android:gravity="center"
android:textSize="#dimen/action_size"
android:hint="Help Desk"/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar1"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="15"
android:fitsSystemWindows="true"
android:theme="#style/Theme"
android:listSelector="#android:color/transparent"
app:popupTheme="#style/MyApp.PopupMenu"
android:gravity="center"
app:titleTextColor="#color/white"
xmlns:app="http://schemas.android.com/apk/res-auto"
/>
</LinearLayout>
<RelativeLayout
android:id="#+id/relativelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/sublinerlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
app:srcCompat="#drawable/ic_profile"
android:tint="#000000"
android:layout_weight="12"/>
<TextView
android:id="#+id/hstudentname"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="82"
android:textSize="#dimen/large_size"
android:textColorHint="#000000"
android:gravity="left|center"/>
</LinearLayout>
<ScrollView
android:id="#+id/help"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:fadeScrollbars="true"
android:scrollbars="vertical"
android:layout_marginBottom="80dp"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:fillViewport="true"
android:fadeScrollbars="true"
android:layout_marginBottom="80dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/idframe"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:padding="2dp"
android:background="#drawable/cardviewhelp"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
><ImageView
android:layout_width="wrap_content"
app:srcCompat="#drawable/ic_ticket"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/subject"
android:layout_width="match_parent"
android:paddingLeft="05dp"
android:paddingRight="05dp"
android:gravity="left|center"
android:textColor="#000000"
android:textSize="#dimen/large_size"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="70"
android:textSize="#dimen/medium_m_size"
android:paddingLeft="10dp"
android:editable="false"
android:hint="hint"
android:focusable="false"
android:scrollbars="vertical"
android:gravity="left|center"
android:textColorHint="#000000"
android:background="#00000000"
android:textColor="#000000"/>
<TextView
android:id="#+id/datetime"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="30"
android:textColor="#000000"
android:hint="date"
android:textSize="#dimen/medium_m_size"
android:gravity="right|bottom"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_below="#+id/idframe"
android:id="#+id/toolbarframelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/simpleSwipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/e_helptoolrecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:stackFromEnd ="true">
</android.support.v7.widget.RecyclerView>
<!--</LinearLayout>-->
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="-80dp"
android:background="#FFFFFF"
android:layout_alignParentBottom="true">
<LinearLayout
android:id="#+id/blow12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100"
android:background="#FFFFFF"
android:gravity="center"
android:layout_gravity="bottom"
android:layout_margin="3dp">
<EditText
android:id="#+id/AddReplay"
android:background="#drawable/cardviewhelp"
android:layout_width="0dp"
android:layout_weight="84"
android:hint="Type a Message"
android:maxLength="200"
android:layout_height="match_parent"
android:layout_marginLeft="12dp"
android:focusable="true"
android:lines="3"
android:scrollbars="vertical"
android:scrollIndicators="start|end"
android:gravity="left|top"
android:inputType="textMultiLine|textFilter"
android:textColor="#000000"
android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890~`\n !##$%^*()_ -+=|\;;'.,/?"
tools:targetApi="m"/>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="16"
android:layout_marginLeft="10dp"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/replaybutton"
android:layout_width="wrap_content"
android:src="#mipmap/send"
android:layout_height="wrap_content"
app:civ_border_color="#800080"
app:civ_border_width="2dp"/>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_below="#+id/blow12"
android:id="#+id/textcount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginBottom="5dp"
android:textColor="#color/helpdesk_color"
android:text="200 Character Remaining"/>
</RelativeLayout>
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:orientation="horizontal"-->
<!--android:weightSum="100"-->
<!--android:layout_alignParentBottom="true"-->
<!--android:background="#FFFFFF"-->
<!--android:layout_gravity="bottom"-->
<!--android:layout_margin="3dp">-->
<!--<com.xw.repo.XEditText-->
<!--android:id="#+id/AddReplay"-->
<!--android:background="#drawable/cardviewhelp"-->
<!--android:layout_width="0dp"-->
<!--android:layout_weight="85"-->
<!--android:hint="Type a Message"-->
<!--android:maxLength="200"-->
<!--android:layout_height="wrap_content"-->
<!--android:padding="2dp"-->
<!--android:layout_alignParentBottom="true"-->
<!--android:layout_marginLeft="12dp"-->
<!--android:focusable="true"-->
<!--android:gravity="left|center"-->
<!--android:inputType="textMultiLine|textFilter"-->
<!--android:textColor="#000000"-->
<!--app:x_disableEmoji="true"/>-->
<!--<de.hdodenhof.circleimageview.CircleImageView-->
<!--android:id="#+id/replaybutton"-->
<!--android:layout_width="0dp"-->
<!--android:src="#mipmap/send"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_weight="16"-->
<!--android:padding="2dp"-->
<!--app:civ_border_color="#800080"-->
<!--app:civ_border_width="2dp"/>-->
<!--</LinearLayout>-->
</RelativeLayout>
</LinearLayout>
<!--</android.support.v4.widget.NestedScrollView>-->
</RelativeLayout>
`
My problem : scrolling only this below layout.but not working whole scrolling in Relative Layout.
`
<LinearLayout
android:id="#+id/idframe"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:padding="2dp"
android:background="#drawable/cardviewhelp"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
><ImageView
android:layout_width="wrap_content"
app:srcCompat="#drawable/ic_ticket"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/subject"
android:layout_width="match_parent"
android:paddingLeft="05dp"
android:paddingRight="05dp"
android:gravity="left|center"
android:textColor="#000000"
android:textSize="#dimen/large_size"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="70"
android:textSize="#dimen/medium_m_size"
android:paddingLeft="10dp"
android:editable="false"
android:hint="hint"
android:focusable="false"
android:scrollbars="vertical"
android:gravity="left|center"
android:textColorHint="#000000"
android:background="#00000000"
android:textColor="#000000"/>
<TextView
android:id="#+id/datetime"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="30"
android:textColor="#000000"
android:hint="date"
android:textSize="#dimen/medium_m_size"
android:gravity="right|bottom"/>
</LinearLayout>
</LinearLayout>
`
RecyclerView itself a ScrollView .
Solution
Call NestedScrollView instead of ScrollView .
STRUCTURE
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
/>
</android.support.v4.widget.NestedScrollView>
FYI
You should add
recyclerViewOBJ.setNestedScrollingEnabled(false);
If this property is set to true the view will be permitted to initiate
nested scrolling operations with a compatible parent view in the
current hierarchy. If this view does not implement nested scrolling
this will have no effect. Disabling nested scrolling while a nested
scroll is in progress has the effect of stopping the nested scroll.
You should take a scrollview outside of Relative layout
Set your Scrollview to NestedScrollView
<android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.RecyclerView>
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>
In your recyclerview
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setHasFixedSize(false);
Related
I have a ScrollView in my app and inside it I have created a Linear Layout which contains various elements but the problem is this my buttons on bottom are not displayed properly. They are cut off at bottom. I have used padding and margin but nothing has been happened. Below is my layout
<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="#color/light_gray">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/dp10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/dp20"
android:layout_marginRight="#dimen/dp20"
android:layout_marginTop="#dimen/dp30"
android:orientation="vertical">
<ImageView
android:id="#+id/imgArticleImage"
android:layout_width="match_parent"
android:layout_height="#dimen/dp140"
android:layout_marginBottom="#dimen/dp15"
android:background="#android:color/white"
android:scaleType="fitXY"
android:src="#drawable/banner" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_grey_border_white_bg">
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/dp5"
android:text="#string/title"
android:textColor="#android:color/black" />
<android.support.design.widget.TextInputLayout
android:id="#+id/ettxtLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/txtTitle"
android:padding="#dimen/dp5"
app:counterEnabled="true"
app:counterMaxLength="100"
app:counterTextAppearance="#style/TextLimitStyle">
<android.support.design.widget.TextInputEditText
android:id="#+id/etTitile"
android:layout_width="match_parent"
android:layout_height="#dimen/dp80"
android:background="#android:color/transparent"
android:gravity="top"
android:maxLength="100" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dp20"
android:background="#drawable/bg_grey_border_white_bg">
<TextView
android:id="#+id/txtTitleDes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/dp5"
android:text="#string/start_writing"
android:textColor="#android:color/black" />
<android.support.design.widget.TextInputLayout
android:id="#+id/ettxtLayoutDes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/txtTitleDes"
android:padding="#dimen/dp5"
app:counterEnabled="true"
app:counterMaxLength="1200"
app:counterTextAppearance="#style/TextLimitStyle">
<android.support.design.widget.TextInputEditText
android:id="#+id/etDescription"
android:layout_width="match_parent"
android:layout_height="#dimen/dp140"
android:background="#android:color/transparent"
android:gravity="top"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/layNew"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="#dimen/dp10"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/btnSave_draft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp10"
android:layout_marginRight="#dimen/dp20"
android:background="#android:color/holo_blue_light"
android:paddingLeft="#dimen/dp10"
android:paddingRight="#dimen/dp10"
android:text="#string/save_draft"
android:textColor="#android:color/white" />
<Button
android:id="#+id/btnPublish_article"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:background="#android:color/holo_blue_light"
android:paddingLeft="#dimen/dp10"
android:paddingRight="#dimen/dp10"
android:text="#string/publish_your_article"
android:textColor="#android:color/white"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/layUpdate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="#dimen/dp10"
android:gravity="center"
android:orientation="horizontal"
>
<Button
android:id="#+id/btnDiscardChanges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp10"
android:layout_marginRight="#dimen/dp20"
android:background="#android:color/holo_blue_light"
android:paddingLeft="#dimen/dp10"
android:paddingRight="#dimen/dp10"
android:text="#string/discard_changes"
android:textColor="#android:color/white" />
<Button
android:id="#+id/btnSaveChanges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:background="#android:color/holo_blue_light"
android:paddingLeft="#dimen/dp10"
android:paddingRight="#dimen/dp10"
android:text="#string/save_changes"
android:textColor="#android:color/white"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<ProgressBar
android:id="#+id/pBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone" />
`
Can anyone suggest me what I have missed?
Wrap up another LinearLayout under the ScrollView and give
paddingBottom to the Second child (the second LinearLayout)
so add this to the added linearLayout :-
android:paddingBottom="20dp"
Correct order for padding :-
ScrollView
||
LinearLayout X- X -- > padding Bottom wont be applied
||
LinearLayout with paddingBottom -- > is applicable
Note :- paddingBottom and marginBottom cannot be applied to the immediate child of the ScrollView.
Remove
android:paddingBottom="#dimen/dp10"
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/dp10">
Just add android:paddingBottom="#dimen/dp30" into your LinearLayout:
<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="#color/light_gray">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/dp10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/dp20"
android:layout_marginRight="#dimen/dp20"
android:layout_marginTop="#dimen/dp30"
android:orientation="vertical"
android:paddingBottom="#dimen/dp30">
I have the following layout consisting of several text boxes which I want to scroll as one object. I then have a linear layout below that which contains navigation buttons - I want this to stick to the bottom of the screen and not scroll.
Right now the bottom linear layout is pushed off the screen - I suspect because of the setting of the height of the scroll view. However I can't see the trick to resolve this. How can I make it so that the buttons in the linear view are always visible and stick to the bottom of the screen (not the bottom of the scrollview)?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:paddingLeft="8dp"
android:paddingRight="8dp"
tools:context="com.QuestionView">
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<ScrollView
android:id="#+id/ScrollView"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:scrollbars="horizontal">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:orientation="vertical">
<TextView
android:id="#+id/questionText"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical"
android:text="TextView"
android:textSize="24dp" />
<TextView
android:id="#+id/answerA"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical"
android:text="TextView"
android:textSize="24dp" />
<TextView
android:id="#+id/answerB"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical"
android:text="TextView"
android:textSize="24dp" />
<TextView
android:id="#+id/answerC"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical"
android:text="TextView"
android:textSize="24dp" />
<TextView
android:id="#+id/answerD"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical"
android:text="TextView"
android:textSize="24dp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/back"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#ff9933"
android:text="Back" />
<Button
android:id="#+id/flip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#1a75ff"
android:text="Flip" />
<Button
android:id="#+id/next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#ff9933"
android:text="Next" />
</LinearLayout>
</LinearLayout>
Use a RelativeLayout for the outer layout. Define the Linear layout with buttons to be layout_alignParentBottom. Make the ScrollView layout_above the button layout and layout_below the toolbar (which should be alignParentTop). Then the buttons will be on the bottom, the toolbar on top, and the scroll view between them.
Best way to do this is to use android.support.design.widget.CoordinatorLayout to get Button Layout at bottom use android:layout_gravity="bottom" like below
Step 1:
Add compile 'com.android.support:design:26.1.0'
step 2:
<android.support.design.widget.CoordinatorLayout
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.QuestionView">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/questionText"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical"
android:text="TextView"
android:textSize="24dp" />
<TextView
android:id="#+id/answerA"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical"
android:text="TextView"
android:textSize="24dp" />
<TextView
android:id="#+id/answerB"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical"
android:text="TextView"
android:textSize="24dp" />
<TextView
android:id="#+id/answerC"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical"
android:text="TextView"
android:textSize="24dp" />
<TextView
android:id="#+id/answerD"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical"
android:text="TextView"
android:textSize="24dp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal">
<Button
android:id="#+id/back"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#ff9933"
android:text="Back" />
<Button
android:id="#+id/flip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#1a75ff"
android:text="Flip" />
<Button
android:id="#+id/next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#ff9933"
android:text="Next" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
This is the xml code for my fragment.I'm able to display the linear layout on top of recyclerview but the problem is, the linear layout doesn't align in bottom of screen.
Should I use relative layout instead of framelayout?
<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"
tools:context="com.example.dell.pollachiclient.MyCartFragment">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_cart"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:background="#Fff"
>
<TextView
android:id="#+id/setup_macroSavebtn"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_gravity="start"
android:gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:textColor="#000"
android:background="#Fff"
android:textStyle="normal"
android:textSize="22sp"
android:text="$500.00"/>
<Button
android:id="#+id/setup_macroCancelbtn"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:gravity="center_vertical|center_horizontal"
android:layout_margin="10dp"
android:layout_weight="1"
android:textColor="#fff"
android:background="#FA631D"
android:text="Checkout"/>
</LinearLayout>
</FrameLayout>
Screenshot
Use RelativeLayout instead of FrameLayout and use
android:layout_alignParentBottom="true"
in the LinearLayout which you want to appear at the bottom.
User RelativeLayout and go with
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal"
android:background="#Fff"
android:layout_below="#id/recycler_view_cart"
>
<?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:background="#color/White">
<Recycalvire
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/view_a" />
<View
android:id="#+id/view_a"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#+id/bottom_layout"
android:background="#color/col1"></View>
<Linearlayout
layout="#layout/buttom_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Try this as answered by #Nabin Bhandari
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_cart"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_gravity="bottom"
android:background="#Fff"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<TextView
android:id="#+id/setup_macroSavebtn"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_gravity="start"
android:layout_weight="1"
android:background="#Fff"
android:gravity="center_vertical|center_horizontal"
android:text="$500.00"
android:textColor="#000"
android:textSize="22sp"
android:textStyle="normal" />
<Button
android:id="#+id/setup_macroCancelbtn"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_margin="10dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:background="#FA631D"
android:gravity="center_vertical|center_horizontal"
android:text="Checkout"
android:textColor="#fff" />
</LinearLayout>
</RelativeLayout>
My EditText looks like:
<EditText
android:id="#+id/uuidInput"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textSize="14sp"
android:inputType="text"/>
However, when I run my app, the EditText does not get focus on touch I dont know why.
I have a layout file beacon_data_input.xml which is included inside activity_main.xml
Here is my input view beacon_data_input.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:id="#+id/inputLayout"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="visible">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beacon UUID:"/>
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="* "
android:textColor="#color/red" />
<EditText
android:id="#+id/uuidInput"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textSize="14sp"
android:focusableInTouchMode="true"
android:inputType="text"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beacon Major:"/>
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="* "
android:textColor="#color/red"/>
<EditText
android:id="#+id/majorInput"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textSize="14sp"
android:focusableInTouchMode="true"
android:inputType="number"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beacon Minor:"/>
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="* "
android:textColor="#color/red"/>
<EditText
android:id="#+id/minorInput"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textSize="14sp"
android:focusableInTouchMode="true"
android:inputType="number"/>
</LinearLayout>
activity_main.xml includes the above layout as:
<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:orientation="vertical"
android:fitsSystemWindows="true">
<include layout="#layout/custom_toolbar" />
<include layout="#layout/beacon_data_input" />
<android.support.v7.widget.RecyclerView
android:layout_marginTop="56dp"
android:id="#+id/proximityRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"></android.support.v7.widget.RecyclerView>
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedButton
android:gravity="center"
android:id="#+id/StartButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:background="#292d2e"
android:textColor="#48c68f"
android:textSize="24sp"
android:layout_alignParentBottom="true"
android:text="Start"
/>
<LinearLayout
android:orientation="vertical"
android:id="#+id/imageLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
</RelativeLayout>
Thanks in Advance.
Your EditText is not getting touch because in activity_main.xml file, its getting overlap by RecyclerView & LinearLayout..
Try to put it like following (Add your edittextLayout over of each layout):
<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:orientation="vertical"
android:fitsSystemWindows="true">
<android.support.v7.widget.RecyclerView
android:layout_marginTop="56dp"
android:id="#+id/proximityRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"></android.support.v7.widget.RecyclerView>
<com.nicbit.proximitydemo.common.customviews.RobotoCondensedButton
android:gravity="center"
android:id="#+id/StartButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:background="#292d2e"
android:textColor="#48c68f"
android:textSize="24sp"
android:layout_alignParentBottom="true"
android:text="Start"
/>
<LinearLayout
android:orientation="vertical"
android:id="#+id/imageLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
<!--- Add them in last -->
<include layout="#layout/custom_toolbar" />
<include layout="#layout/beacon_data_input" />
</RelativeLayout>
or try after setting the visibility of that RecyclerView & RobotoCondensedButton's & LinearLayout's visibility GONE.
This Worked for me
android:windowSoftInputMode="adjustPan"
add this line in your menifest in your activity.
I have a problem with my XML layout, something that I thought wouldn't give me many problems. I have a layout below in a scroll view, but the bottom of the layout is being cut off, I can't see anything past the second list view. From looking around, I can't seem to see anything wrong with the xml itself and I can't see what I am doing wrong.
I have tried the suggestion to the problem, that is adding a weight to each of the different elements but this still hasnt solved the problem.
I have also added the main activity in which the fragment is placed incase that might help solve the problem
Fragment XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/coordinatorLayout">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Recipe Title"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:id="#+id/ingredientsHeading"
android:layout_below="#+id/text_input_layout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Ingredients"
android:textStyle="bold|italic"
android:layout_weight="1" />
<ListView
android:id="#+id/ingredientsList"
android:layout_below="#+id/ingredientsHeading"
android:layout_above="#+id/directionsHeading"
android:layout_width="wrap_content"
android:layout_height="195dp"
android:layout_weight="1"></ListView>
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Ingredient"
android:id="#+id/addIngredient"
android:layout_below="#+id/ingredientsList"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<TextView
android:id="#+id/directionsHeading"
android:layout_below="#+id/addIngredient"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Directions"
android:textStyle="bold|italic"
android:layout_weight="1" />
<ListView
android:id="#+id/directionsList"
android:layout_below="#+id/directionsHeading"
android:layout_width="wrap_content"
android:layout_height="195dp"
android:layout_weight="1"></ListView>
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Direction"
android:id="#+id/addDirection"
android:layout_below="#+id/ingredientsList"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/filterButton"
app:backgroundTint="#color/floatingButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:clickable="true"
android:src="#drawable/ic_filter"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="63dp"
android:layout_marginRight="16dp" />
</android.support.design.widget.CoordinatorLayout>
Main XML
<android.support.v4.widget.DrawerLayout
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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout2">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<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/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<FrameLayout
android:id="#+id/container_body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</android.support.design.widget.CoordinatorLayout>
<fragment
android:id="#+id/fragment_navigation_drawer"
android:name="com.example.rory.pocketchef.Fragments.FragmentDrawer"
android:layout_width="#dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="#layout/fragment_navigation_drawer"
tools:layout="#layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
I solved the issue. As the scroll view was being displayed the bottom was being cut off by the bottom action bar on the actual phone. So to solve this I added padding to the bottom of the scrollview in order to push it back up above the action bar.
The new layout it as follows
Updated working XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/coordinatorLayout">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="vertical"
android:paddingBottom="?android:attr/actionBarSize"> <<<-------added this line
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Recipe Title"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:id="#+id/ingredientsHeading"
android:layout_below="#+id/text_input_layout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Ingredients"
android:textStyle="bold|italic"
android:layout_weight="1" />
<ListView
android:id="#+id/ingredientsList"
android:layout_below="#+id/ingredientsHeading"
android:layout_above="#+id/directionsHeading"
android:layout_width="wrap_content"
android:layout_height="195dp"
android:layout_weight="1"></ListView>
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Ingredient"
android:id="#+id/addIngredient"
android:layout_below="#+id/ingredientsList"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<TextView
android:id="#+id/directionsHeading"
android:layout_below="#+id/addIngredient"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Directions"
android:textStyle="bold|italic"
android:layout_weight="1" />
<ListView
android:id="#+id/directionsList"
android:layout_below="#+id/directionsHeading"
android:layout_width="wrap_content"
android:layout_height="195dp"
android:layout_weight="1"></ListView>
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Direction"
android:id="#+id/addDirection"
android:layout_below="#+id/ingredientsList"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_below="#+id/addDirection">
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Direction"
android:id="#+id/showOptionsDialog"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Direction"
android:id="#+id/saveRecipe"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_toRightOf="#+id/showOptionsDialog"
android:layout_weight="1" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/filterButton"
app:backgroundTint="#color/floatingButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:clickable="true"
android:src="#drawable/ic_filter"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="63dp"
android:layout_marginRight="16dp" />
</android.support.design.widget.CoordinatorLayout>
Add these lines in your ScrollView
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="vertical">
use weightSum for all components in your xml file,
It's android:layout_weight. Weight can only be used in LinearLayout. If the orientation of linearlayout is Vertical, then use android:layout_height="0dp" and if the orientation is horizontal, then use android:layout_width = "0dp". It'll work perfectly.
From your question -- bottom of the layout is being cut off
It is because of fixed height given to components.
EDIT -- xml added
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
tools:context="info.androidhive.materialtabs.fragments.OneFragment">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="none"
android:fillViewport="true"
android:isScrollContainer="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="10">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Recipe Title" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="3.5"
android:orientation="vertical">
<TextView
android:id="#+id/ingredientsHeading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Ingredients"
android:textStyle="bold|italic" />
<ListView
android:id="#+id/ingredientsList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<Button
android:id="#+id/addIngredient"
style="#style/AppTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:enabled="true"
android:text="Add Ingredient" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="3.5"
android:orientation="vertical">
<TextView
android:id="#+id/directionsHeading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Directions"
android:textStyle="bold|italic" />
<ListView
android:id="#+id/directionsList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<Button
android:id="#+id/addDirection"
style="#style/AppBaseTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:enabled="true"
android:text="Add Direction" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
You put a weightsum of 1 and your scrollview is 28. You have to put something like that <LinearLayout weightsum=15>(you don't have to put 15) and then what is inside your layout you have to distribute your 15 sum. Like <TextView layout_weight=1> it means that your textview is gonna 1/15. When I use weight I also put the height or the width, depending on which one I want to play, to 0dp. For exemple if I want to play on the width <TextView width=0dp height=wrap_content weight=1>. So you have to give a weight to every child of your LinearLayout.
Hope it help.
Edit: Also ListView in a ScrollView is not a good idea, could come from here. Look this post:
How can I put a ListView into a ScrollView without it collapsing?