how to use scrollview in layout with toolbar and bottomnavigationview? - android

I have a screen in which there is a toolbar, a bottomNavigationView and some data between them including a textView and an imageView. I want to scroll the inner data that is between the toolbar and bottomNavigationView.
I want to scroll the design.xml inside of main.xml. Please suggest a way I can achieve this.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar1"
android:layout_width="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
xmlns:app="http://schemas.android.com/apk/res-auto">
<include
layout="#layout/design"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</ScrollView>
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#FFFFFF"
app:itemTextColor="#FFFFFF"
app:menu="#menu/bottom_navigation_main" />
design.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="?android:attr/actionBarSize"
tools:context="com.example.chaitanya.pg.Pgdata">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/relative">
<Button
android:id="#+id/btt1"
android:background="#drawable/tprevoius"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="100dp" />
<Button
android:background="#drawable/tnext"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignTop="#+id/btt1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/btt2" />
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="250dp"
android:id="#+id/viewPager"/>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:id="#+id/cardview1"
android:layout_width="match_parent"
android:layout_height="100dp"
card_view:cardElevation="5dp"
android:layout_below="#id/viewPager"
android:layout_margin="6dp"
card_view:cardBackgroundColor="#FFF"
card_view:cardCornerRadius="7dp"
card_view:cardMaxElevation="5dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Facilities"
android:textColor="#color/colorPrimary"
android:textAllCaps="true"
android:id="#+id/facilities"
android:textSize="20dp"
android:gravity="center"
android:layout_below="#+id/viewPager"
android:textColorHighlight="#color/colorPrimary"
android:textStyle="bold|italic" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:orientation="horizontal"
>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:paddingLeft="10dp"
android:textSize="15dp"
android:id="#+id/wifi"
/>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_gravity="center"
android:gravity="center"
android:foregroundGravity="center"
android:textSize="15dp"
android:id="#+id/ac"
/>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:foregroundGravity="right"
android:paddingLeft="20dp"
android:id="#+id/food"
android:textStyle="bold"
android:textSize="15dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:id="#+id/cardview12"
android:layout_width="match_parent"
android:layout_height="60dp"
card_view:cardElevation="5dp"
android:layout_below="#id/cardview1"
android:layout_margin="6dp"
card_view:cardBackgroundColor="#FFF"
card_view:cardCornerRadius="7dp"
card_view:cardMaxElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Accomodation"
android:textColor="#color/colorPrimary"
android:textAllCaps="true"
android:textSize="20dp"
android:gravity="center"
android:textColorHighlight="#color/colorPrimary"
android:textStyle="bold|italic" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="2dp"
android:layout_gravity="center"
android:gravity="center"
android:foregroundGravity="center"
android:textSize="20dp"
android:id="#+id/accomodation"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:id="#+id/cardview123"
android:layout_width="match_parent"
android:layout_height="60dp"
card_view:cardElevation="5dp"
android:layout_below="#id/cardview12"
android:layout_margin="6dp"
card_view:cardBackgroundColor="#FFF"
card_view:cardCornerRadius="7dp"
card_view:cardMaxElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Price"
android:textColor="#color/colorPrimary"
android:textAllCaps="true"
android:textSize="20dp"
android:gravity="center"
android:textColorHighlight="#color/colorPrimary"
android:textStyle="bold|italic" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="2dp"
android:layout_gravity="center"
android:gravity="center"
android:foregroundGravity="center"
android:textSize="20dp"
android:id="#+id/pricee"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:id="#+id/name"
android:textColor="#FFFFFF"
android:textStyle="italic"
android:textSize="20dp"
android:layout_marginLeft="10dp"
android:paddingLeft="20dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/name"
android:id="#+id/addr"
android:textColor="#FFFFFF"
android:textStyle="italic"
android:layout_marginLeft="10dp"
android:textSize="20dp"
/>
</RelativeLayout>
</LinearLayout>

There needs to be only one layout inside ScrollView.
You do not need to put ScrollView inside ScrollView.
You have added the include tag inside the ScrollView and your
design.xml also has ScrollView.
I would not use android:fillViewport tag inside ScrollView, instead
use properties related to relative layout.
Rest of the things don't seem too difficult to figure out.

from design.xml remove parent <ScrollView> because outsie you already define the scrollview so there is no use of scrollview inside the design.xml
design.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
xmlns:app="http://schemas.android.com/apk/res-auto">

Related

Not able to set the Frame Layout height to Match Parent

I Have Two Fragment class for my project, On my first FragmentA, I have added a FrameLayout to the FragmentA xml file,named as filter_pop_up_frame_lyt_container. so on a button click from from FragmentA, Im adding a new FragmentB to the framelayout of FragmentA. so my intention was to see the framelayout height to be match parent. When my recyclerView items in FragmentA is loaded, the height of the Frame Layout taking only the height of the FragmentB . How can we make the framelayout matchparent.
Tried with this solution :FrameLayout height not matching parent , but not working for me.
sampleCode for my FragmentA xml File:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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"
android:background="#color/tastry_btn_txt"
tools:openDrawer="start">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<com.agrawalsuneet.dotsloader.loaders.CircularDotsLoader
android:id="#+id/circle_dot_loader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:elevation="100dp"
android:foregroundGravity="center"
android:visibility="visible"
app:loader_bigCircleRadius="25dp"
app:loader_circleRadius="5dp"
app:loader_defaultColor="#color/blue_dark"
app:loader_firstShadowColor="#color/lit_grey6"
app:loader_secondShadowColor="#color/lit_grey4"
app:loader_selectedColor="#color/lit_grey3"
app:loader_showRunningShadow="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- The ActionBar displayed at the top -->
<androidx.appcompat.widget.Toolbar xmlns:app="http://schemas.android.com/tools"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/palate_survey_bg"
app:ignore="NamespaceTypo"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<androidx.appcompat.widget.SearchView
android:id="#+id/Advance_search"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginEnd="50dp"
android:background="#drawable/filter_search_bar_bg_lyt"
app:iconifiedByDefault="false"
app:queryHint="Search">
</androidx.appcompat.widget.SearchView>
<View
android:id="#+id/filter_loc_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="20dp"
android:layout_marginTop="40dp"
android:background="#99a3bc" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"></LinearLayout>
</androidx.appcompat.widget.Toolbar>
<LinearLayout
android:id="#+id/search_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar"
android:background="#66100202"
android:clickable="true"
android:orientation="vertical"
android:translationZ="15dp"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:fontFamily="sans-serif-medium"
android:text="Popular Searches"
android:textColor="#color/white"
android:textSize="22dp"
android:textStyle="normal">
</TextView>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_advance_search"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/tastry_btn_txt"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/filter_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/filter">
</ImageView>
<TextView
android:id="#+id/filter_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:fontFamily="sans-serif-medium"
android:text="Filter By"
android:textColor="#color/white"
android:textSize="22sp"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:id="#+id/filter_container_lyt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/filter_layout"
android:layout_alignParentTop="true"
android:layout_marginTop="2dp"
android:background="#495471"
android:gravity="center_vertical"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view_filter_category"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabTextAppearance="#android:style/TextAppearance.Widget.TabWidget" />
</LinearLayout>
<RelativeLayout
android:id="#+id/wine_complete_lyt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/filter_layout"
android:layout_marginStart="3dp"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view_red_wine_category"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp" />
</RelativeLayout>
<FrameLayout
android:id="#+id/filter_pop_up_frame_lyt_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/filter_layout"
android:background="#color/orange"
android:elevation="50dp"
android:translationZ="30dp" />
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
</RelativeLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/palate_survey_bg"
android:fitsSystemWindows="true"
app:headerLayout="#layout/header"
app:itemIconSize="20dp"
app:itemIconTint="#color/white"
app:itemTextColor="#color/white"
app:menu="#menu/drawermenu" />
</androidx.drawerlayout.widget.DrawerLayout>
sampleCode for FragmentB layout:
<?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"
android:id="#+id/linear_layout_root_price_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#66FF0000"
android:orientation="vertical">
<!-- android:background="#drawable/filter_bg_round_corner"-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/filter_bg_round_corner"
android:orientation="vertical">
<LinearLayout
android:id="#+id/progress_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:orientation="vertical">
<com.google.android.material.slider.RangeSlider
android:id="#+id/filter_price_ranger_Slider"
style="#style/Theme.TastrySampleApp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progressDrawable="#drawable/progress_layout_bg"
android:stepSize="1"
android:theme="#style/Theme.TastrySampleApp"
android:valueFrom="0.0"
android:valueTo="100.0"
app:labelBehavior="gone"
app:thumbColor="#01b0c3"
app:tickVisible="false"
app:values="#array/initial_slider_values" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/onStartTrackingTouch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:ellipsize="end"
android:maxLines="1"
android:text="$0"
android:textColor="#color/black"
android:textSize="16sp">
</TextView>
<TextView
android:id="#+id/onStopTrackingTouch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:ellipsize="end"
android:maxLines="1"
android:text="$100+"
android:textColor="#color/black"
android:textSize="16sp">
</TextView>
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="10dp"
android:layout_marginTop="20dp"
android:background="#99a3bc">
</View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:gravity="right"
android:orientation="horizontal"
android:padding="14dp">
<TextView
android:id="#+id/filter_price_wine_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:text="1234"
android:textColor="#color/black"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="gone">
</TextView>
<TextView
android:id="#+id/filter_price_wine_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="0"
android:ellipsize="end"
android:maxLines="1"
android:text="Wines"
android:textColor="#color/black"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="gone">
</TextView>
<View
android:layout_width="0dp"
android:layout_height="10dp"
android:layout_gravity="center"
android:layout_weight="1" />
<LinearLayout
android:id="#+id/filter_price_root_clear_lyt"
android:layout_width="110dp"
android:layout_height="35dp"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_toLeftOf="#+id/filter_price_Apply"
android:background="#drawable/filter_clear_bg"
android:gravity="center"
android:visibility="gone">
<ImageView
android:id="#+id/close_filter_price"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:src="#drawable/close_white">
</ImageView>
<TextView
android:id="#+id/clear_price_filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginTop="3dp"
android:layout_toRightOf="#id/close_filter_price"
android:text="Clear All"
android:textColor="#f2faff"
android:textStyle="bold">
</TextView>
<TextView
android:id="#+id/price_clear_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="3dp"
android:layout_toRightOf="#id/clear_price_filter"
android:textColor="#f2faff"
android:textStyle="bold">
</TextView>
</LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="#+id/filter_price_Apply"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:background="#drawable/filter_apply_bg"
android:gravity="center"
android:text="Apply"
android:textAllCaps="false"
android:textColor="#f2faff"
android:textSize="12sp"
android:visibility="gone">
</com.google.android.material.button.MaterialButton>
</LinearLayout>
</LinearLayout>
</LinearLayout>
When I removed the scrollview from the layout , the height of the frame layout was set to match parent. Worked perfectly.

How do i place image in android toolbar?

how do I design profile picture like in this image in android? I tried placing it in the toolbar it won't show half below the toolbar.
Here is a look at the code I am trying. I am using a linear layout at top and then again a linear layout for holding logo and text and the image is at the bottom in root linear layout. Despite setting margin-top it still there and not moving to location:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"
tools:menu="#menu/action_menu"
android:background="#color/colorPink1"
android:elevation="0dp"
android:layout_margin="0dp"
app:collapseIcon="#drawable/logo_mini"
android:padding="0dp"
android:layout_height="wrap_content" android:minHeight="0dp">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top"
android:orientation="vertical" android:gravity="end" android:dividerPadding="100dp">
<LinearLayout
android:orientation="vertical"
android:id="#+id/main_layout"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:padding="5dp"
android:paddingLeft="50dp"
android:gravity="center">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/center_icon"
android:layout_gravity="center"
android:src="#drawable/logo_mini"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginTop="5dp"
/>
</LinearLayout>
<ImageView
android:layout_marginTop="5dp"
android:id="#+id/bar"
android:src="#drawable/bar"
android:background="#android:color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:text="Hi ,"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/emp_name" android:textSize="30sp"/>
<TextView
android:text="Wellcome back,"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/textView5"/>
<TextView android:layout_width="match_parent" android:visibility="gone" android:layout_height="wrap_content"
android:text="here ae you assigned sites"/>
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_gravity="bottom|end"
android:elevation="10dp"
android:src="#drawable/user_photo"
android:layout_alignBottom="#+id/center_icon"
android:layout_width="72dp"
android:layout_height="72dp"
android:gravity='center'
android:layout_marginTop="-50dp"
/>
</android.support.v7.widget.Toolbar>
you should use CoordinatorLayout and layout_anchor ,layout_anchorGravity attributes for the ImageView to locate the image on the edge of the toolbar
<android.support.design.widget.CoordinatorLayout
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.support.v7.widget.Toolbar
android:id="#+id/toolbar"
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="wrap_content"
android:layout_margin="0dp"
android:background="#color/colorAccent"
android:elevation="0dp"
android:minHeight="0dp"
android:padding="0dp"
app:collapseIcon="#drawable/logo_mini">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:dividerPadding="100dp"
android:gravity="end"
android:orientation="vertical">
<LinearLayout
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp"
android:paddingLeft="50dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/center_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_weight="0"
android:src="#drawable/logo_mini" />
</LinearLayout>
<ImageView
android:id="#+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#android:color/white"
android:src="#mipmap/mic" />
<TextView
android:id="#+id/emp_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hi ,"
android:textSize="30sp" />
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Wellcome back,"
android:visibility="gone" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="here ae you assigned sites"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<ImageView
android:id="#+id/icon"
android:layout_width="#dimen/dim150"
android:layout_height="#dimen/dim150"
android:layout_below="#+id/home_txt"
android:layout_marginTop="#dimen/dim20"
android:src="#drawable/user_photo"
app:layout_anchor="#id/toolbar"
app:layout_anchorGravity="bottom|center_horizontal" />
</android.support.design.widget.CoordinatorLayout>
you can change your layout like this,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar 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="wrap_content"
android:layout_margin="0dp"
android:background="#color/colorAccent"
android:elevation="0dp"
android:minHeight="0dp"
android:padding="0dp"
app:collapseIcon="#drawable/logo_mini">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:dividerPadding="100dp"
android:gravity="end"
android:orientation="vertical">
<LinearLayout
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp"
android:paddingLeft="50dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/center_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_weight="0"
android:src="#drawable/logo_mini" />
</LinearLayout>
<ImageView
android:id="#+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#android:color/white"
android:src="#mipmap/mic" />
<TextView
android:id="#+id/emp_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hi ,"
android:textSize="30sp" />
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Wellcome back,"
android:visibility="gone" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="here ae you assigned sites"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<ImageView
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignParentRight="true"
android:layout_marginTop="80dp"
android:elevation="10dp"
android:gravity='center'
android:src="#drawable/user_photo" />
</RelativeLayout>
Try to use Constraint Layout to make responsive UI
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".StartActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="#color/colorPrimary">
</android.support.v7.widget.Toolbar>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="24dp"
android:background="#color/colorAccent"
android:src="#drawable/ic_launcher_foreground"
app:layout_constraintBottom_toBottomOf="#+id/toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar" /></android.support.constraint.ConstraintLayout>

Layout gravity bottom is not being applied

The below is my xml file in which i want a linearlayout to be in bottom i.e. layout gravity bottom. But it is not working.
Even after looking all solutions given for this type of problem, i am not able to solve it. Please Help
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar_layout" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewCart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" //----> not working
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/total"
android:textStyle="bold" />
<TextView
android:id="#+id/textViewTotalPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="$23.00" />
</LinearLayout>
<Button
android:id="#+id/buttonCheckout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="20dp"
android:layout_weight="1"
android:background="#color/colorPrimary"
android:drawableEnd="#drawable/ic_arrow_forward"
android:paddingEnd="15dp"
android:text="#string/checkout"
android:textColor="#color/white" />
</LinearLayout>
This is the way i want.
Try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar_layout" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewCart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="total"
android:textStyle="bold" />
<TextView
android:id="#+id/textViewTotalPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="$23.00" />
</LinearLayout>
<Button
android:id="#+id/buttonCheckout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="20dp"
android:background="#color/colorPrimary"
android:drawableEnd="#drawable/ic_arrow_forward"
android:paddingEnd="15dp"
android:text="#string/checkout"
android:textColor="#color/white" />
</LinearLayout>
</LinearLayout>
Put Space layout between RecyclerView and LinearLayout
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
or use RelativeLayout instead of your main LinearLayout
Try this code.. and change this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar_layout" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewCart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="tees"
android:textStyle="bold" />
<TextView
android:id="#+id/textViewTotalPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="$23.00" />
</LinearLayout>
<Button
android:id="#+id/buttonCheckout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="20dp"
android:layout_weight="1"
android:background="#color/colorPrimary"
android:paddingEnd="15dp"
android:text="Hello" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>

How to anchor ImageView to layout

I'm trying to anchor ImageView to layout as below
We can anchor FloatingActionButton but how to anchor a Imageview
I'm not using CoordinatorLayout. i'm using LinearLayout
How can i do that
Try this
<?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:id="#+id/activity_account_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#color/colorPrimary" />
<ScrollView
android:id="#+id/scrolView_account"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/linear_account"
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:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/cardView_account_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="70dp"
app:cardCornerRadius="5dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorAccent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linear_account_input_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="NILU"
android:textSize="30sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#mipmap/ic_launcher_round"
android:hint="Enter Email" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#mipmap/ic_launcher_round"
android:hint="Enter Paasword" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Login" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="This is demo" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imageview_account_profile"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#mipmap/ic_launcher_round"
app:civ_border_color="#color/colorWhite"
app:civ_border_width="2dp" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>

XML layout design and code are not matching

My xml layout design is not what it is supposed to be from my code. I am not changing anything dynamically.
Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/rollnoT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="5"
android:textSize="200sp"/>
<TextView
android:id="#+id/nameT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rollnoT"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:text="abc"
android:textSize="30sp"/>
<TextView
android:id="#+id/cmtT"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:alpha="0"
android:background="#android:color/holo_red_light"
android:gravity="center_vertical|center_horizontal"
android:text="Ab"
android:textSize="200sp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
My design:
Look at "abc" It should be below '5' not in mid.
I have set android:layout_below="#+id/rollnoT"
but still it is shown in mid.
Pls help me solve this issue.
Try this
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/rollnoT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="5"
android:textSize="200sp"/>
<TextView
android:id="#+id/nameT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rollnoT"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:text="abc"
android:textSize="30sp"/>
<TextView
android:id="#+id/cmtT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:alpha="0"
android:background="#android:color/holo_red_light"
android:gravity="center_vertical|center_horizontal"
android:text="Ab"
android:textSize="200sp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
Try this blow snippet,
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/rollnoT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="5"
android:textSize="200sp" />
<TextView
android:id="#+id/nameT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rollnoT"
android:layout_marginTop="19dp"
android:text="abc"
android:textSize="30sp" />
</LinearLayout>
<TextView
android:id="#+id/cmtT"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:alpha="0"
android:background="#android:color/holo_red_light"
android:gravity="center_vertical|center_horizontal"
android:text="Ab"
android:textSize="200sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
It would be great if you have practice about LinearLayout. It solves lots of issues. If you are using RelativeLayout then it is dependable on other views.

Categories

Resources