I want to create a scrollview with items I add programmatically and at the bottom a fixed button. But with the code below I see no button.
The code:
<LinearLayout
android:id="#+id/list_warrantys"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:id="#+id/show_warratys"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/add_warranty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#drawable/mybutton"
android:text="#string/add_button"
android:layout_marginBottom="5dp"/>
</LinearLayout>
<RelativeLayout android:id="#+id/list_warrantys"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:layout_above="#+id/add_warranty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="#+id/show_warratys"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/add_warranty"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#drawable/mybutton"
android:text="#string/add_button"
android:layout_marginBottom="5dp"/>
Use RelativeLayout as root and set android:layout_alignParentBottom="true" to your button and android:layout_above="#+id/add_warranty" to your ScrollView
Related
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:id="#+id/lnrUpper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/lnrUpSide"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/purple_200"
android:orientation="vertical" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/lnrUpSide"
android:background="#color/white">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBarLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:elevation="0dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:fitsSystemWindows="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="225dp"
android:background="#FFF000" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
<LinearLayout
android:id="#+id/fixedHeader"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#color/black"
android:clickable="false"
android:focusable="false">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="FIXED HEADER VIEW"
android:textColor="#color/white"
android:textSize="24sp" />
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fixedHeader">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="75dp"
android:background="#F0FE">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#FF0E">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#color/black">
</LinearLayout>
</LinearLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="125dp"
android:background="#color/purple_700">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="SECOND FIXED HEADER VIEW"
android:textColor="#color/white"
android:textSize="24sp" />
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="1200dp"
android:background="#color/teal_700">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.core.widget.NestedScrollView>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</RelativeLayout>
</RelativeLayout>
This is my layout xml file and this is how it looks.
This is how my layout look in the first place
When I scroll the layout becomes like this.
Scrolled Layout
However, that is not what I want.
This is the layout I want when I scroll it completely
I was only able to take a screenshot from Android Studio because when I start this at phone the SECOND FIXED HEADER VIEW not got fixed at top. I have tried so many ways but I could not find a solution for this issue. Does anyone know how to make this view ?
I want to build a UI with responsive design, so I use layout weights. It seems like ScrollView won't scroll with weights. I've tried using ScrollView without weights and the scrolling works fine. I wonder if there's a way to use ScrollView with weights. Here's my code:
<ScrollView 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:fillViewport="true"
android:orientation="vertical"
tools:context=".MainActivity">
<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"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:background="#color/colorAccent"
android:layout_weight="0.3"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:background="#color/colorPrimary"
android:layout_weight="0.7">
<Button
android:layout_width="match_parent"
android:layout_height="200dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="200dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="200dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="200dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="Last Button"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Any help will be appreciated, thanks!
Nested weights are bad for performance. But if you badly need this, You need to remove fixed height of buttons and need to set weight as per weightsum and height should be 0. Make changes as below -
<ScrollView 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:fillViewport="true"
android:orientation="vertical"
tools:context=".MainActivity">
<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"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:background="#color/colorAccent"
android:layout_weight="0.3"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:background="#color/colorPrimary"
android:layout_weight="0.7"
android:weightSum="5">
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Last Button"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
So my button and edit text widgets keep getting pushed upwards when I dynamically add text views to my scroll view. So the scrollview's height is also being bumped up. How do I just make sure the scroll view is fixed, I've looked at similar questions and tried implementing it but not working.
<?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:windowSoftInputMode="stateVisible|adjustPan"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="#+id/name"
android:hint="Enter name"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"/>
<EditText
android:id="#+id/phone_num"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:hint="Enter Phone Number"/>
<Button
android:id="#+id/submit"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:text="#string/submit_contact"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:isScrollContainer="false"
android:fillViewport="true">
<LinearLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
</LinearLayout>
Try to set all heights to 0dp and give the wheightSum to the parent view. To have a fixed height of the button surround it with a LinearLayout.
<?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:windowSoftInputMode="stateVisible|adjustPan"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2.75"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="#+id/name"
android:hint="Enter name"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"/>
<EditText
android:id="#+id/phone_num"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:hint="Enter Phone Number"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:orientation="vertical">
<Button
android:id="#+id/submit"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:text="test"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:isScrollContainer="false"
android:fillViewport="true">
<LinearLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
</LinearLayout>
Try it out, If it dont work you may post what you have tried alredy and the code how you ad the textViews dynamicly. Good luck
Haii.... i need help to design my imageView from this screen shoot to be like this i need the imageView crossed from layout, i am using some of library in this activity like SlidingUpPanel and imageview from CircleImageView if i want to search in google what the keyword or anyone can give me any solution?
here is my layout.xml :
<?xml version="1.0" encoding="utf-8"?>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="100dp"
sothree:umanoParallaxOffset="100dp"
sothree:umanoShadowHeight="20dp"
sothree:umanoDragView="#+id/dragView"
tools:context="com.idiots_international.jajan.activities.nearby.NearbyActivity"
sothree:umanoOverlay="true">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_gravity="top"
android:layout_height="wrap_content"
android:orientation="vertical">
<fragment 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:id="#+id/map"
tools:context="com.idiots_international.jajan.activities.nearby.MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
</LinearLayout>
<!--map/top view-->
<RelativeLayout android:id="#+id/nearbyRelLayout1" android:layout_width="match_parent" android:layout_height="wrap_content">
<!---->
<LinearLayout android:layout_width="match_parent"
android:background="#color/colorWhite"
android:layout_height="wrap_content"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center"
android:src="#drawable/jajan_logo_3"
app:civ_border_width="2dp"
app:civ_border_color="#FF000000"/>
<TextView
android:id="#+id/ShowAddressTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Click on Marker to view Address "
android:textColor="#000"
android:textSize="15dp"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"/>
<ScrollView android:layout_width="match_parent" android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/recyclerView"
android:layout_alignParentTop="false"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</android.support.v7.widget.RecyclerView>
</ScrollView>
</LinearLayout>
<include layout="#layout/layout_bottom_navigation"/>
</RelativeLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
Working but need to remove the outline in here :
Try this,
<!--map/top view-->
<RelativeLayout
android:background="#android:color/transparent"
android:id="#+id/nearbyRelLayout1" android:layout_width="match_parent" android:layout_height="wrap_content">
<!---->
<LinearLayout
android:layout_marginTop="50dp"
android:layout_width="match_parent"
android:background="#color/colorWhite"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/ShowAddressTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Click on Marker to view Address "
android:textColor="#000"
android:textSize="15dp"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"/>
<ScrollView android:layout_width="match_parent" android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/recyclerView"
android:layout_alignParentTop="false"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</android.support.v7.widget.RecyclerView>
</ScrollView>
</LinearLayout>
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:src="#drawable/jajan_logo_3"
app:civ_border_width="2dp"
app:civ_border_color="#FF000000"/>
</RelativeLayout>
Don't use white background for the parent of Circle image view, this will not let see background map.
You can implement this with following layout idea. Feel free to ask if you cant reach requirement
<?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"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
// margin top half of circle image view height
android:layout_marginTop="40dp"
>
</LinearLayout>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
Try this way:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
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">
<LinearLayout
android:background="#643122"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<!--Your Top view (the map) goes here-->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<!--Your Bottom view (the text) goes here-->
</LinearLayout>
</LinearLayout>
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center"
android:src="#drawable/bg"
app:civ_border_width="2dp"
app:civ_border_color="#FF000000"/>
</FrameLayout>
OUTPUT IMAGE
I want to display my notification_bar_linearlayout on top of the ScrollView.
In code after the data in ScrollView has been populate I will then show the notification_bar_linearlayout.
But When I show:
notification_bar_linearlayout.setVisibility(View.VISIBLE);
The data inside the ScrollView will auto scroll to the middle.
Meaning that in the screen it will have as visible the following:
notification_bar_linearlayout
block_two
Therefor block_one is no longer visible.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
//Notification bar
<LinearLayout
android:id="#+id/notification_bar_linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="#color/white_color"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:paddingTop="15dip"
android:paddingBottom="15dip"
android:visibility="gone">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
//My TextView for the bar
</RelativeLayout>
</LinearLayout>
//List datas
<ScrollView
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">
<LinearLayout
android:id="#+id/block_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
//My frist block for the top of the list
</LinearLayout>
<LinearLayout
android:id="#+id/block_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
//My second block for the bottom of the list
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
P.S. There reason for so many LinearLayout is because I have some custom data showing horizontal and others vertical.
Without a screenshot is difficult of understand but maybe you need to set weight in this manner:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
//Notification bar
<LinearLayout
android:layout_weight="0.5"
android:id="#+id/notification_bar_linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="#color/white_color"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:paddingTop="15dip"
android:paddingBottom="15dip"
android:visibility="gone">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
//My TextView for the bar
</RelativeLayout>
</LinearLayout>
//List datas
<ScrollView
android:layout_weight="0.5"
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">
<LinearLayout
android:id="#+id/block_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
//My frist block for the top of the list
</LinearLayout>
<LinearLayout
android:id="#+id/block_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
//My second block for the bottom of the list
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</FrameLayout>
</LinearLayout>