main layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:clipToPadding="true"
android:paddingStart="16dp"
android:paddingEnd="32dp">
<include
android:id="#+id/sideBar"
layout="#layout/layout_side_bar"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<TextView
android:id="#+id/tv_name"
style="#style/ListItemText"
android:layout_alignParentTop="true"
android:layout_marginTop="21dp"
android:layout_toEndOf="#id/sideBar"
android:gravity="center"
android:letterSpacing="-0.02"
android:text="#string/xyz"
android:textColor="#color/blue"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_name"
android:layout_marginStart="8dp"
android:layout_marginTop="9dp"
android:layout_marginBottom="18dp"
android:layout_toEndOf="#id/sideBar"
android:background="#drawable/bg_text_new"
android:drawableStart="#drawable/ic_wait_icon"
android:drawablePadding="14dp"
android:fontFamily="sans-serif"
android:gravity="center_vertical"
android:lineSpacingExtra="6sp"
android:paddingStart="14dp"
android:paddingTop="9dp"
android:paddingEnd="14dp"
android:paddingBottom="9dp"
android:text="#string/abc"
android:textColor="#color/primary"
android:textSize="13sp" />
</RelativeLayout>
layout_side_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<View
android:id="#+id/v_lineTop"
android:layout_width="2dp"
android:layout_height="20dp"
android:background="#color/green" />
<TextView
android:id="#+id/tv_number"
style="#style/ListItemNumber"
android:background="#drawable/bg_circle"
tools:text="2" />
<View
android:id="#+id/v_lineBottom"
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/grey" />
</LinearLayout>
The view with id v_lineBottom in the layout_side_bar that is included in the main layout is invisible.
It only shows up if I give a specific height to the v_lineBottom view or to the included android:id="#+id/sideBar"
I am using the main layout as a recycler view item
I am getting a view like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:clipToPadding="true"
android:paddingStart="16dp"
android:paddingEnd="32dp"
android:paddingRight="32dp"
android:paddingLeft="16dp">
<include
android:id="#+id/sideBar"
layout="#layout/layout_side_bar"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<TextView
android:id="#+id/tv_name"
android:layout_alignParentTop="true"
android:layout_marginTop="21dp"
android:layout_toEndOf="#id/sideBar"
android:gravity="center"
android:letterSpacing="-0.02"
android:text="xys"
android:textColor="#color/blue"
android:textStyle="bold"
android:layout_toRightOf="#id/sideBar"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<TextView
android:id="#+id/tv_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_name"
android:layout_marginStart="8dp"
android:layout_marginTop="9dp"
android:layout_marginBottom="18dp"
android:layout_toEndOf="#id/sideBar"
android:drawablePadding="14dp"
android:fontFamily="sans-serif"
android:gravity="center_vertical"
android:lineSpacingExtra="6sp"
android:paddingStart="14dp"
android:paddingTop="9dp"
android:paddingEnd="14dp"
android:paddingBottom="9dp"
android:text="#string/acre"
android:textColor="#color/black"
android:textSize="13sp"
android:layout_marginLeft="8dp"
android:layout_toRightOf="#id/sideBar" />
</RelativeLayout>
and layout_side_bar
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<View
android:id="#+id/v_lineTop"
android:layout_width="2dp"
android:layout_height="20dp"
android:background="#color/blue" />
<TextView
android:id="#+id/tv_number"
tools:text="2"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<View
android:id="#+id/v_lineBottom"
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/black" />
</LinearLayout>
can you show graphical representation of your view the way you want to achieve..
Related
I'm trying to create a recyclerview of cards. I get the information from the firebase realtime database but cards didn't fill the width of screen.
find_tournament.xml:
<?xml version="1.0" encoding="utf-8"?>
<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:background="#3E2743"
android:orientation="vertical"
tools:context=".FindTournamentActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:orientation="vertical">
<ImageView
android:id="#+id/tournamentImageParticipant"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"/>
<TextView
android:id="#+id/tournamentLabelParticipant"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="#font/baloo"
android:text="Tournament Name"
android:textAlignment="center"
android:textColor="#color/jitrino"
android:textSize="20sp" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="20dp"/>
</LinearLayout>
</ScrollView>
Desing view of find tournament:
find_tournament.xml
tournament_row.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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="wrap_content"
android:elevation="20dp"
app:cardBackgroundColor="#4F2A36"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp">
<ImageView
android:id="#+id/tournamentImageRow"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#mipmap/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:orientation="vertical">
<TextView
android:id="#+id/tournamentNameRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tournament Name"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/tournamentGameRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tournament Game"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/tournamentRewardRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reward"
android:textColor="#color/white"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:orientation="horizontal">
<TextView
android:id="#+id/tournamentPersonRow"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center_vertical"
android:text="N"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center_vertical"
android:text="Vs"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/tournamentPerson2Row"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center_vertical"
android:text="N"
android:textColor="#color/white"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
Desing view of tournament row:
tournament_row.xml
Here is the result when i run the app. How can i fill gaps?
result
<androidx.cardview.widget.CardView 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="wrap_content"
android:elevation="20dp"
app:cardBackgroundColor="#4F2A36"
app:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp">
<ImageView
android:id="#+id/tournamentImageRow"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#mipmap/ic_launcher" />
<LinearLayout
android:layout_toRightOf="#id/tournamentImageRow"
android:layout_toLeftOf="#+id/end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:orientation="vertical">
<TextView
android:id="#+id/tournamentNameRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tournament Name"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/tournamentGameRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tournament Game"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/tournamentRewardRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reward"
android:textColor="#color/white"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/tournamentImageRow"
android:layout_alignBottom="#id/tournamentImageRow"
android:layout_alignParentRight="true"
android:layout_marginLeft="20dp"
android:orientation="horizontal">
<TextView
android:id="#+id/tournamentPersonRow"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center_vertical"
android:text="N"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center_vertical"
android:text="Vs"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/tournamentPerson2Row"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center_vertical"
android:text="N"
android:textColor="#color/white"
android:textSize="20sp" />
</LinearLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>
The width of the LinearLayout below the image is wrap_content. You can go around this problem by using weight.
Refer to this link for more information about weight
https://android--examples.blogspot.com/2016/06/android-understanding-linearlayout.html
Please note that it is recommended to use ConstraintLayout.
I have the following xml file -
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/white"
android:orientation="vertical">
<ImageView
android:id="#+id/fragment_terms_and_conditions_back_image"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:src="#drawable/arrow_left" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:text="#string/fragment_terms_and_conditions_terms_and_conditions"
android:textColor="#color/black"
android:textSize="20sp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="#dimen/main_app_top_margin_15dp"
android:layout_marginEnd="24dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_bold"
android:text="#string/terms_and_conditions_fragment_overview"
android:textColor="#color/color_light_gray"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:textSize="15sp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/main_app_top_margin_15dp"
android:text="#string/terms_and_conditions_fragment_overview_content"
android:textColor="#color/black" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="15dp"
android:background="#color/color_list_divider_color" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/main_app_top_margin_15dp"
android:fontFamily="#font/roboto_bold"
android:text="#string/terms_and_conditions_fragment_terms_prohibited_use"
android:textColor="#color/color_light_gray"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/main_app_top_margin_15dp"
android:text="#string/terms_and_conditions_fragment_terms_prohibited_use_content"
android:textColor="#color/black" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="15dp"
android:background="#color/color_list_divider_color" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_bold"
android:text="#string/terms_and_conditions_fragment_terms_post_sales_support"
android:textColor="#color/color_light_gray"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/main_app_top_margin_15dp"
android:text="#string/terms_and_conditions_fragment_terms_post_sales_support_content"
android:textColor="#color/black" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="15dp"
android:background="#color/color_list_divider_color" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/roboto_bold"
android:text="#string/terms_and_conditions_fragment_terms_illegal_distribution"
android:textColor="#color/color_light_gray"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/main_app_top_margin_15dp"
android:layout_marginBottom="30dp"
android:text="#string/terms_and_conditions_fragment_terms_illegal_distribution_content"
android:textColor="#color/black" />
</LinearLayout>
</ScrollView>
</LinearLayout>
but the Scrollview does not show the scrollbar like the following picture -
I tried to add android:fadeScrollbars="false" and android:scrollbarFadeDuration="0" and nothing works
I tried also to put the fadescrollbars to true and add some durations to the fade and it does not have any effect
what am I missing?
As shown in image it have recyclerview of list and each recyclerviews item has again new recyclerview which contains list of images. the red area is getting captures click event but from same item nested recyclerview area/item not getting clicked.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_marginBottom="6dp"
android:background="#color/colorWhite"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/ll_offer_product_item"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:paddingTop="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_marginRight="8dp"
android:src="#drawable/ic_user"
android:id="#+id/img_user"
android:layout_width="42dp"
android:layout_height="42dp" />
<TextView
android:textColor="#color/colorNickname"
android:textSize="16sp"
android:id="#+id/lbl_nickname"
android:layout_toRightOf="#+id/img_user"
android:text="U*36"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_below="#+id/lbl_nickname"
android:layout_toRightOf="#+id/img_user"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:src="#drawable/ic_positive_sm"
android:layout_width="14dp"
android:layout_height="14dp" />
<TextView
android:id="#+id/lbl_positive"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="32"
android:textColor="#color/colorTextDefault"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:src="#drawable/ic_negative_sm"
android:layout_width="14dp"
android:layout_height="14dp" />
<TextView
android:id="#+id/lbl_negative"
android:layout_marginLeft="5dp"
android:text="1"
android:textColor="#color/colorTextDefault"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
<TextView
android:id="#+id/lbl_product_name"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textSize="17sp"
android:textStyle="bold"
android:textColor="#color/colorProductName"
android:text="Apple iPhone 6, 128GB, White "
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingBottom="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:src="#drawable/ic_location"
android:layout_width="14dp"
android:layout_height="14dp" />
<TextView
android:textColor="#color/darkerGray"
android:id="#+id/txt_kms"
android:text="1km"
android:textSize="12sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:duplicateParentState="true"
android:clickable="false"
android:id="#+id/recyclerView_offer_product_images"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:scrollbars="none" />
<RelativeLayout
android:paddingTop="8dp"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textColor="#color/colorTimeEndsIn"
android:id="#+id/txt_endsin"
android:padding="8dp"
android:text="00:30"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:background="#color/colorOfferProductPrice"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:gravity="right"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lbl_currency"
android:textColor="#color/colorWhite"
android:paddingRight="2dp"
android:text="d"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:maxLines="1"
android:ellipsize="end"
android:textStyle="bold"
android:id="#+id/lbl_price"
android:textColor="#color/colorWhite"
android:text="24.750.000"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
And for nested recyclerview following is xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:clickable="false"
android:duplicateParentState="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.android.volley.toolbox.NetworkImageView
android:clickable="false"
android:duplicateParentState="true"
android:id="#+id/img_offer_product"
android:scaleType="centerCrop"
android:layout_width="100dp"
android:layout_height="100dp" />
<View
android:background="#color/colorLightGray"
android:layout_width="1px"
android:layout_height="match_parent" />
</LinearLayout>
try to set clickable attribute true as above,
<android.support.v7.widget.RecyclerView
android:duplicateParentState="true"
android:clickable="true"
android:id="#+id/recyclerView_offer_product_images"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:scrollbars="none" />
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:orientation="horizontal">
<com.android.volley.toolbox.NetworkImageView
android:id="#+id/img_offer_product"
android:layout_width="100dp"
android:layout_height="100dp"
android:clickable="true"
android:duplicateParentState="true"
android:scaleType="centerCrop" />
<View
android:layout_width="1px"
android:layout_height="match_parent"
android:background="#color/colorLightGray" />
</LinearLayout>
You should make your view clickable.
As I can see that you have clickable false for the view, so you need to change like this for your child item of child recyclerview.
I'm using a scroll view which is having only one child linearlayout.
Linearlayout contains listview and some other items also, but only listview is scrolling. what should i do ?
Here is my layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/beco_white"
android:orientation="vertical">
<include layout="#layout/toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ViewSwitcher
android:id="#+id/view_switcher"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="125dp"
android:background="#android:color/white"
android:orientation="horizontal">
<Button
android:id="#+id/button_sign_in"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="#dimen/dp20"
android:background="#drawable/dark_blue_round_corner"
android:fontFamily="sans-serif-normal"
android:text="Login to beCo"
android:textAllCaps="false"
android:textColor="#android:color/white"
android:textSize="14sp" />
<Button
android:id="#+id/button_sign_up"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="#dimen/dp20"
android:background="#drawable/customborder"
android:fontFamily="sans-serif-normal"
android:text="Create New Account"
android:textAllCaps="false"
android:textColor="#color/colorAccent"
android:textSize="14sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="125dp"
android:background="#android:color/white">
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/image_profile"
android:layout_width="#dimen/dp88"
android:layout_height="#dimen/dp88"
android:layout_gravity="left"
android:layout_marginBottom="#dimen/dp10"
android:layout_marginLeft="#dimen/dp10"
android:layout_marginTop="#dimen/dp10"
fresco:actualImageScaleType="centerCrop"
fresco:placeholderImage="#drawable/no_profile_pic"
fresco:roundAsCircle="true"
fresco:roundingBorderColor="#color/white"
fresco:roundingBorderWidth="#dimen/dp2" />
<TextView
android:id="#+id/user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="#dimen/dp10"
android:layout_toRightOf="#+id/image_profile"
android:fontFamily="sans-serif-normal"
android:text="John Doe"
android:textColor="#android:color/black"
android:textSize="25sp" />
<TextView
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/user_name"
android:layout_marginLeft="#dimen/dp10"
android:layout_toEndOf="#+id/image_profile"
android:layout_toRightOf="#+id/image_profile"
android:fontFamily="sans-serif-normal"
android:text="johndoe#mail.com"
android:textColor="#android:color/black"
android:textSize="14sp" />
<Button
android:id="#+id/button_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/image_profile"
android:background="#drawable/customborder"
android:text="Edit Profile"
android:textAllCaps="false"
android:textColor="#color/colorAccent" />
</RelativeLayout>
</ViewSwitcher>
<View
android:layout_width="wrap_content"
android:layout_height="1dp"
android:background="#color/grey_200" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Any one please help me?
Never put A ListView inside a ScrollView. It is a bad practice and it defeats the purpose of having a ListView. Who wants two scrollable areas on a screen anyway?
Instead add a header or footer view on your listView depending on what you need.
If you look at the documentation https://developer.android.com/reference/android/widget/ScrollView.html it states that scrollview should never be used with listview there may be a conflict between them.
Try this layout:
changes:
Make your inner linearlayout wrap into Scrollview
Apply android:layout_height="wrap_content" for scrollview
End the scrollview before Listview as both can not be applied together
<?xml version="1.0" encoding="utf-8"?>
<include layout="#layout/toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ViewSwitcher
android:id="#+id/view_switcher"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="125dp"
android:background="#android:color/white"
android:orientation="horizontal">
<Button
android:id="#+id/button_sign_in"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="#dimen/dp20"
android:background="#drawable/dark_blue_round_corner"
android:fontFamily="sans-serif-normal"
android:text="Login to beCo"
android:textAllCaps="false"
android:textColor="#android:color/white"
android:textSize="14sp" />
<Button
android:id="#+id/button_sign_up"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="#dimen/dp20"
android:background="#drawable/customborder"
android:fontFamily="sans-serif-normal"
android:text="Create New Account"
android:textAllCaps="false"
android:textColor="#color/colorAccent"
android:textSize="14sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="125dp"
android:background="#android:color/white">
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/image_profile"
android:layout_width="#dimen/dp88"
android:layout_height="#dimen/dp88"
android:layout_gravity="left"
android:layout_marginBottom="#dimen/dp10"
android:layout_marginLeft="#dimen/dp10"
android:layout_marginTop="#dimen/dp10"
fresco:actualImageScaleType="centerCrop"
fresco:placeholderImage="#drawable/no_profile_pic"
fresco:roundAsCircle="true"
fresco:roundingBorderColor="#color/white"
fresco:roundingBorderWidth="#dimen/dp2" />
<TextView
android:id="#+id/user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="#dimen/dp10"
android:layout_toRightOf="#+id/image_profile"
android:fontFamily="sans-serif-normal"
android:text="John Doe"
android:textColor="#android:color/black"
android:textSize="25sp" />
<TextView
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/user_name"
android:layout_marginLeft="#dimen/dp10"
android:layout_toEndOf="#+id/image_profile"
android:layout_toRightOf="#+id/image_profile"
android:fontFamily="sans-serif-normal"
android:text="johndoe#mail.com"
android:textColor="#android:color/black"
android:textSize="14sp" />
<Button
android:id="#+id/button_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/image_profile"
android:background="#drawable/customborder"
android:text="Edit Profile"
android:textAllCaps="false"
android:textColor="#color/colorAccent" />
</RelativeLayout>
</ViewSwitcher>
</LinearLayout>
</ScrollView>
<View
android:layout_width="wrap_content"
android:layout_height="1dp"
android:background="#color/grey_200" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Use NestedScrollView instead of ScrollView.
NestedScrollView is just like ScrollView, but it supports acting
as both a nested scrolling parent and child on both new and old
versions of Android.
See the Documentation
Update your XML as below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/beco_white"
android:orientation="vertical">
<include layout="#layout/toolbar" />
<android.support.v4.widget.NestedScrollView
android:id="#+id/layout_scorll"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants">
<ViewSwitcher
android:id="#+id/view_switcher"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="125dp"
android:background="#android:color/white"
android:orientation="horizontal">
<Button
android:id="#+id/button_sign_in"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="#dimen/dp20"
android:background="#drawable/dark_blue_round_corner"
android:fontFamily="sans-serif-normal"
android:text="Login to beCo"
android:textAllCaps="false"
android:textColor="#android:color/white"
android:textSize="14sp" />
<Button
android:id="#+id/button_sign_up"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="#dimen/dp20"
android:background="#drawable/customborder"
android:fontFamily="sans-serif-normal"
android:text="Create New Account"
android:textAllCaps="false"
android:textColor="#color/colorAccent"
android:textSize="14sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="125dp"
android:background="#android:color/white">
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/image_profile"
android:layout_width="#dimen/dp88"
android:layout_height="#dimen/dp88"
android:layout_gravity="left"
android:layout_marginBottom="#dimen/dp10"
android:layout_marginLeft="#dimen/dp10"
android:layout_marginTop="#dimen/dp10"
fresco:actualImageScaleType="centerCrop"
fresco:placeholderImage="#drawable/no_profile_pic"
fresco:roundAsCircle="true"
fresco:roundingBorderColor="#color/white"
fresco:roundingBorderWidth="#dimen/dp2" />
<TextView
android:id="#+id/user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="#dimen/dp10"
android:layout_toRightOf="#+id/image_profile"
android:fontFamily="sans-serif-normal"
android:text="John Doe"
android:textColor="#android:color/black"
android:textSize="25sp" />
<TextView
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/user_name"
android:layout_marginLeft="#dimen/dp10"
android:layout_toEndOf="#+id/image_profile"
android:layout_toRightOf="#+id/image_profile"
android:fontFamily="sans-serif-normal"
android:text="johndoe#mail.com"
android:textColor="#android:color/black"
android:textSize="14sp" />
<Button
android:id="#+id/button_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/image_profile"
android:background="#drawable/customborder"
android:text="Edit Profile"
android:textAllCaps="false"
android:textColor="#color/colorAccent" />
</RelativeLayout>
</ViewSwitcher>
<View
android:layout_width="wrap_content"
android:layout_height="1dp"
android:background="#color/grey_200" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
I found the solution by using only with the listview. ie., removing scrollview, and by using headerview for the listview
Xml code for listview
<?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:background="#color/beco_white"
android:orientation="vertical">
<include layout="#layout/toolbar" />
<View
android:layout_width="wrap_content"
android:layout_height="1dp"
android:background="#color/grey_200" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#drawable/list_divider"
android:dividerHeight="#dimen/dp1"
android:headerDividersEnabled="false"
android:footerDividersEnabled="false" />
</LinearLayout>
xml code for headerview of listview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ViewSwitcher
android:id="#+id/view_switcher"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/profile_background"
android:orientation="vertical">
<Button
android:id="#+id/button_sign_in"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="#dimen/dp40"
android:background="#drawable/dark_blue_round_corner"
android:fontFamily="sans-serif-medium"
android:text="Sign in"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="14sp" />
<LinearLayout
android:id="#+id/button_sign_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="#dimen/dp16">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fontFamily="sans-serif-normal"
android:text="#string/new_to_beco"
android:textColor="#color/beco_white"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="7dp"
android:fontFamily="sans-serif-normal"
android:text="#string/action_sign_up"
android:textAllCaps="true"
android:textColor="#color/beco_primary"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/profile_background">
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/image_profile"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_gravity="left"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
fresco:actualImageScaleType="centerCrop"
fresco:placeholderImage="#drawable/no_profile_pic"
fresco:roundAsCircle="true"
fresco:roundingBorderColor="#color/white"
fresco:roundingBorderWidth="#dimen/dp2" />
<TextView
android:id="#+id/user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/image_profile"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="25dp"
android:layout_toEndOf="#+id/image_profile"
android:layout_toRightOf="#+id/image_profile"
android:fontFamily="sans-serif-medium"
android:text="John Doe"
android:textColor="#android:color/black"
android:textSize="18sp" />
<TextView
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/user_name"
android:layout_alignStart="#+id/user_name"
android:layout_below="#+id/user_name"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif-normal"
android:text="johndoe#mail.com"
android:textColor="#android:color/black"
android:textSize="13sp" />
<ImageView
android:id="#+id/action_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/email"
android:layout_alignTop="#+id/user_name"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:layout_toEndOf="#+id/user_name"
android:layout_toRightOf="#+id/user_name"
android:src="#drawable/ic_edit" />
</RelativeLayout>
</ViewSwitcher>
Here is my layout XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="wrap_content"
android:orientation="vertical"
android:weightSum="3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#mipmap/banner" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:id="#+id/row2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 1"
android:textColor="#color/darkBlue"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyRecipes"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAll1"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:layout_below="#id/row2" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:id="#+id/row3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 2"
android:textColor="#color/darkBlue"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyFavorites"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAllFavorites"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:layout_below="#id/row3" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
As you can see from my layout, the outer LinearLayout contains 3 RelativeLayout which all have layout_weight equals to 1 and the LinearLayout has weightSum equal to 3.
However, the behavior of the current layout is: The 1st RelativeLayout shared very little space (around 10%) and the 2nd & 3rd RelativeLayout shared 45% of height.
How can I make them equally shared the height?
Add to below attributes to ScrollView
android:layout_centerVertical="true"
android:fadingEdge="none"
android:fillViewport="true"
android:isScrollContainer="true"
Check layout below
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:fadingEdge="none"
android:fillViewport="true"
android:isScrollContainer="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#mipmap/banner" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:id="#+id/row2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 1"
android:textColor="#color/blue_360"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyRecipes"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAll1"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/row2"
android:paddingBottom="5dp"
android:paddingTop="5dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:id="#+id/row3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 2"
android:textColor="#color/blue_360"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyFavorites"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAllFavorites"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/row3"
android:paddingBottom="5dp"
android:paddingTop="5dp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
Because your using scrollview you need to fill your view port to make the scroll view occupy the whole screen
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"/>
//..... your other code here
</ScrollView>