I have following layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_weight="300"
android:layout_height="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/add_ticket_info"
android:visibility="gone"
android:orientation="horizontal">
<TableLayout
</TableLayout>
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/ticket_add_next_button"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:visibility="gone"
/>
</LinearLayout>
The issue is that this table disappears when I programatically set ticket_add_next_button visibility to visible. Scroll appears but I cant see nothing
Related
The list of things expected in the outout
1.a linear layout to the buttom of the activity as shown in the expected image
2.a recycler view above the linear layout to achieve the scrolling funtionality as shown in the expected image
The problem can be solved if I give the height to the recycler view.But in this case the layout won't be responsive to the samller sized screens
How can I achieve it?
xmlfile.xml
<?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:numberpicker="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"
tools:context=".CartPage">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:padding="20dp">
<ImageView
android:id="#+id/back_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:src="#drawable/ic_arrow_back_black_24dp" />
<TextView
android:id="#+id/product_buy"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/back_icon"
android:fontFamily="#font/carter_one"
android:text="My Cart"
android:textColor="#color/black"
android:textSize="20sp"
tools:ignore="RtlCompat" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/product_recycler"
android:layout_width="match_parent"
android:layout_height="400sp"
android:padding="0dp" />
// this is the buttom recycler
<LinearLayout
android:layout_alignParentBottom="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/buttom"
android:gravity="bottom|end"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border_gray"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="#+id/details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border_gray"
android:fontFamily="sans-serif"
android:lineHeight="28dp"
android:padding="5dp"
android:text="Price Details"
android:textColor="#color/grey_400"
android:textSize="18sp"
tools:ignore="RtlCompat" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
If you wish to tell your RecyclerView to fill the left over space of your LinearLayout you have to use the following layout_height and layout_weight on your RecyclerView:
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/product_recycler"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:padding="0dp" />
Here is the code that i'm facing the problem i took 2 linear layout inside scroll view now the last button inside 2nd linear layout is hidden or i can say not showing properly.
Here is the screen shot.
you can check that i selected area is button but not working properly.
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:weightSum="1">
<LinearLayout
android:id="#+id/ConcernedPortionofScreen"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="#+id/RestofScreen"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.75"
android:orientation="vertical"
android:padding="20dp">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/custom_button_shape_with_bg_primary"
android:minHeight="#dimen/minimum_height_all_object"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:text="SELECT"
android:textColor="#color/white"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
when i try to remove layout_weight my layout getting mass.
<android.support.constraint.ConstraintLayout 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="#android:color/white"
android:orientation="vertical"
tools:context=".MainActivity">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:id="#+id/ConcernedPortionofScreen"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:orientation="vertical">
<!-- Parent FrameLayout 'FL' -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Conitans Tree Childs -->
</FrameLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/RestofScreen"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.75"
android:orientation="vertical"
android:padding="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<!--Conitans Two Childs -->
</LinearLayout>
<EditText
style="#style/CustomEdittextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:hint="Enter Child Name"
android:minHeight="#dimen/add_child_rquest_minimum_height_all_object" />
<EditText
style="#style/CustomEdittextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:hint="Select City"
android:minHeight="#dimen/add_child_rquest_minimum_height_all_object" />
<TextView
style="#style/CustomEdittextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:hint="Select Birthdate"
android:minHeight="#dimen/add_child_rquest_minimum_height_all_object" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<!--Conitans Two Childs -->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<!--Conitans Two Childs -->
</LinearLayout>
<EditText
style="#style/CustomEdittextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:hint="Enter Mobile Number"
android:minHeight="#dimen/add_child_rquest_minimum_height_all_object" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<!--Conitans Two Childs -->
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:fontFamily="#font/segoe_ui_bold"
android:paddingLeft="10dp"
android:text="Note / Message :"
android:textColor="#color/colorPrimaryDark"
android:textSize="18dp" />
<EditText
style="#style/CustomEdittextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:inputType="textMultiLine"
android:lines="8"
android:maxLines="8"
android:minHeight="#dimen/add_child_rquest_minimum_height_all_object"
android:minLines="8"
android:scrollbars="vertical" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="#dimen/add_child_rquest_margin_top"
android:background="#drawable/custom_button_shape_with_bg_primary"
android:fontFamily="#font/segoe_ui_bold"
android:minHeight="#dimen/add_child_rquest_minimum_height_all_object"
android:text="SUBMIT"
android:textColor="#color/white" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
This Happends Because of layout_height="match_parent" for ScrollView child LinearLayout
Change layout_height to wrap_content
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
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:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
//childs ..........
</LinearLayout>
<ScrollView>
wrap_content
Setting a View's size to wrap_content will force it to expand only far enough to contain the values (or child controls) it contains. For controls -- like text boxes (TextView) or images (ImageView) -- this will wrap the text or image being shown. For layout elements it will resize the layout to fit the controls / layouts added as its children.
Official Docs Says
FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding)
WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding)
Use nested Scroll View, scroll view will truncate the last item in the layout
add padding from bottom and check.
android:layout_marginBottom="5dp"
android:layout_paddingBottom="10dp"
The simplest solution is placing ConstraintLayout inside ScrollView like this
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="vertical">
<!-- your other views could be here-->
<!-- your other views could be here-->
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
So, i have a linear layout and a textview (both wrapped in scrollview). I want to place textview at bottom of screen initially (I DONT want it to be fixed at the bottom). I followed this question Adding view to bottom of layout inside a scrollview
but it didn't help. Here's my layout. (all layout_width attribute is match_parent)
<ScrollView
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content">
<LinearLayout
android:layout_height="0dp"
android:layout_weight="1">
<!-- this expands to fill the empty space if needed -->
</LinearLayout>
<!-- this sits at the bottom of the ScrollView,
getting pushed out of view if the ScrollView's
content is tall enough -->
<TextView
android:layout_height="wrap_content"
android:text="something">
</TextView>
</LinearLayout>
</ScrollView>
The problem is the textview is never visible. Could you tell what I can do to fix it? (Initially there is enough space for linear layout and textview to fit in screen)
PS: please dont mark as duplicate, as all other related questions want the textview to be FIXED at bottom.
Try this one
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:fillViewport="true">
<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:text="something">
</TextView>
</LinearLayout>
</ScrollView>
<include
layout="#layout/your_edit_text_layout_here"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom" />
</LinearLayout>
Try this.It may solve your problem
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
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:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="text1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="text2" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="something"></TextView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I have the following code:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/activity_list_films">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:onClick="back"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
However the button, and the stuff that I add to the inner LinearLayout dynamically, all appear on the top left of the screen. What am I doing wrong?
I have tried putting layout_gravity="center" and gravity="center" in the inner LinearLayout too, but this does not help.
Thanks.
Your LinearLayout width is wrap_content : it doesn't take the whole width of the screen and cannot center content horizontally. So change it to android:layout_width="match_parent" also set layout_gravity to center_horizontal android:layout_gravity="center_horizontal"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/activity_list_films"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="back"
android:text="Back" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Try this
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity = "center"
android:gravity="center"
android:id="#+id/activity_list_films">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:onClick="back"/>
</LinearLayout>
</ScrollView>
Please set width -> match_parent of LinearLayout
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"<!--change this one -->
android:layout_height="wrap_content"
android:id="#+id/activity_list_films">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:onClick="back"/>
</LinearLayout>
Otherwise you can set you LinesrLayout in center. It will be in center of your ScrollView.
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/activity_list_films"
android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:onClick="back"/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:id="#+id/activity_list_films">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:onClick="back"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
You are missing fillViewPort for ScrollView
You not need to change Height of your Linear Layout inside Scroll View.
If you do that the content inside Scroll View will not scroll.
You just need to give android:layout_gravity="center_horizontal" inside Linear Layout other than keep all the same.
Follow below Layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/activity_list_films"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="back"
android:text="Back" />
</LinearLayout>
</ScrollView>
</LinearLayout>
I've a FrameLayout on my android app but I can't make to scrollable a part of this layout...I've tried some solutions to fix this problem, but I can't find a patch!
Pratically, I would like to see scrollable the linearlayout (maybe, linearlayout is not necessary) between Scrollview tags.
This is my xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.robertot.timereport.com.robertot.timereport.Pages.YearlyStatFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
// Some views to scroll
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/bottom_linear"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_gravity="bottom"
style="#android:style/Widget.Holo.Light.ActionBar.Solid">
<Spinner
android:id="#+id/spnYearY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"/>
<ImageButton
android:id="#+id/btnFilter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_search"
android:background="#null"
android:layout_weight="1"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</FrameLayout>
Thanks!! :)
In a FrameLayout all the content views are one on top of the other, so the normal behaviour is that the Linear Layout hides part of the previous Scrollview. Why don't you use a LinearLayout or a Relative Layout instead of the FrameLayout?
Thanks to #Fernando! I've solved my problem, as is:
<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:orientation="vertical"
tools:context="com.robertot.timereport.com.robertot.timereport.Pages.YearlyStatFragment">
<ScrollView
android:id="#+id/scrollyear"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
//Some views
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/bottom_linear"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_gravity="bottom"
style="#android:style/Widget.Holo.Light.ActionBar.Solid">
<Spinner
android:id="#+id/spnYearY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"/>
<ImageButton
android:id="#+id/btnFilter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_search"
android:background="#null"
android:layout_weight="1"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</LinearLayout>
You can surround the view that you want to be scrollable with a ScrollView, as below:
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff">
// the views here that you want to make scrollable
</ScrollView>