How to keep one layout over another layout in android - android

This is my xml I want to keep one layout over another layout.
I have progress Bar and try again Textview in same place I am doing visible and invisible Textview and Progressbar programatically, so I want keep Progressbar over try again button, but I am unable to do this.
I have searched from google that we can do using Frame layout but its not working.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/tesco_blue"
android:paddingBottom="#dimen/margin_18"
android:paddingLeft="#dimen/margin_18"
android:paddingRight="#dimen/margin_12"
android:orientation="vertical"
android:paddingTop="#dimen/margin_18">
<LinearLayout
android:id="#+id/securebarcode_error_layout_variant_a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:layout_marginLeft="#dimen/margin_56"
android:layout_marginRight="#dimen/margin_56"
android:visibility="visible"
tools:visibility="visible">
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="#dimen/margin_40" />
<TextView
android:id="#+id/errortitle"
style="#style/Typeface.Body.Bold.White"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/transparent"
android:gravity="center"
android:lineSpacingExtra="4sp"
tools:text="#string/pwp_network_error" />
<TextView
android:id="#+id/errordesc"
style="#style/Typeface.Body.White"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_marginTop="#dimen/margin_12"
android:lineSpacingExtra="8sp"
tools:text="#string/pwp_network_error_description" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
>
<ProgressBar
android:id="#+id/pwp_progressbarlayout_variant_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:visibility="visible"
android:paddingLeft="#dimen/cl_48"
android:paddingRight="#dimen/cl_48"
android:paddingTop="#dimen/padding_12"
android:paddingBottom="#dimen/padding_12"
android:indeterminateDrawable="#drawable/custom_progress_bar"/>
</FrameLayout>
<TextView
android:id="#+id/try_again"
style="#style/Typeface.Body.Bold.HighlightBlue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#drawable/error_button_background"
android:gravity="center"
android:paddingLeft="#dimen/cl_48"
android:paddingRight="#dimen/cl_48"
android:paddingTop="#dimen/padding_12"
android:paddingBottom="#dimen/padding_12"
android:text="#string/Tryagain"
android:textColor="#color/fdv_pending_state_color" />
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="#dimen/margin_40" />
</LinearLayout>
</LinearLayout>

You can simply use constraint layout in your case as basically its
from the family of frame layout , you can implement the code below.just take your root layout as ConstraintLayout
<TextView
android:id="#+id/try_again"
style="#style/Typeface.Body.Bold.HighlightBlue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:background="#drawable/error_button_background"
android:gravity="center"
android:paddingLeft="#dimen/cl_48"
android:paddingRight="#dimen/cl_48"
android:paddingTop="#dimen/padding_12"
android:paddingBottom="#dimen/padding_12"
android:text="#string/Tryagain"
android:textColor="#color/fdv_pending_state_color" />
<ProgressBar
android:id="#+id/pwp_progressbarlayout_variant_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="#id/try_again"
app:layout_constraintBottom_toBottomOf="#id/try_again"
app:layout_constraintLeft_toLeftOf="#id/try_again"
app:layout_constraintRight_toRightOf="#id/try_again"
android:visibility="visible"
android:paddingLeft="#dimen/cl_48"
android:paddingRight="#dimen/cl_48"
android:paddingTop="#dimen/padding_12"
android:paddingBottom="#dimen/padding_12"
android:indeterminateDrawable="#drawable/custom_progress_bar"/>

You have to move your try_again TextView to inside of FrameLayout so the your Progressbar will show on TextView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/tesco_blue"
android:orientation="vertical"
android:paddingLeft="#dimen/margin_18"
android:paddingTop="#dimen/margin_18"
android:paddingRight="#dimen/margin_12"
android:paddingBottom="#dimen/margin_18">
<LinearLayout
android:id="#+id/securebarcode_error_layout_variant_a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="#dimen/margin_56"
android:layout_marginRight="#dimen/margin_56"
android:orientation="vertical"
android:visibility="visible"
tools:visibility="visible">
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="#dimen/margin_40" />
<TextView
android:id="#+id/errortitle"
style="#style/Typeface.Body.Bold.White"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/transparent"
android:gravity="center"
android:lineSpacingExtra="4sp"
tools:text="#string/pwp_network_error" />
<TextView
android:id="#+id/errordesc"
style="#style/Typeface.Body.White"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="#dimen/margin_12"
android:gravity="center"
android:lineSpacingExtra="8sp"
tools:text="#string/pwp_network_error_description" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center">
<ProgressBar
android:id="#+id/pwp_progressbarlayout_variant_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminateDrawable="#drawable/custom_progress_bar"
android:paddingLeft="#dimen/cl_48"
android:paddingTop="#dimen/padding_12"
android:paddingRight="#dimen/cl_48"
android:paddingBottom="#dimen/padding_12"
android:visibility="visible" />
<TextView
android:id="#+id/try_again"
style="#style/Typeface.Body.Bold.HighlightBlue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/error_button_background"
android:gravity="center"
android:paddingLeft="#dimen/cl_48"
android:paddingTop="#dimen/padding_12"
android:paddingRight="#dimen/cl_48"
android:paddingBottom="#dimen/padding_12"
android:text="#string/Tryagain"
android:textColor="#color/fdv_pending_state_color" />
</FrameLayout>
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="#dimen/margin_40" />
Here it is the image what you want.

Update your Layout as below - Relative Layout can do the trick
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/tesco_blue"
android:paddingBottom="#dimen/margin_18"
android:paddingLeft="#dimen/margin_18"
android:paddingRight="#dimen/margin_12"
android:orientation="vertical"
android:paddingTop="#dimen/margin_18">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/securebarcode_error_layout_variant_a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:layout_marginLeft="#dimen/margin_56"
android:layout_marginRight="#dimen/margin_56"
android:visibility="visible"
tools:visibility="visible">
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="#dimen/margin_40" />
<TextView
android:id="#+id/errortitle"
style="#style/Typeface.Body.Bold.White"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/transparent"
android:gravity="center"
android:lineSpacingExtra="4sp"
tools:text="#string/pwp_network_error" />
<TextView
android:id="#+id/errordesc"
style="#style/Typeface.Body.White"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_marginTop="#dimen/margin_12"
android:lineSpacingExtra="8sp"
tools:text="#string/pwp_network_error_description" />
<TextView
android:id="#+id/try_again"
style="#style/Typeface.Body.Bold.HighlightBlue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#drawable/error_button_background"
android:gravity="center"
android:paddingLeft="#dimen/cl_48"
android:paddingRight="#dimen/cl_48"
android:paddingTop="#dimen/padding_12"
android:paddingBottom="#dimen/padding_12"
android:text="#string/Tryagain"
android:textColor="#color/fdv_pending_state_color" />
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="#dimen/margin_40" />
</LinearLayout>
<ProgressBar
android:id="#+id/pwp_progressbarlayout_variant_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_centerInParent="true"
android:visibility="visible"
android:indeterminateDrawable="#drawable/custom_progress_bar"/>
</RelativeLayout>
</LinearLayout>

Related

Recyclerview is not scrolling

The .xml file is attached below.
The issue is my recycler view is not scrolling.
Also, to show how I'm adding Linearlayout manager, the code is below.
variantRecycler.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
ViewCompat. setNestedScrollingEnabled(variantRecycler, false);
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:background="#color/transparent"
android:layout_height="match_parent">
<TextView
android:id="#+id/cross_icon"
style="#style/icon"
android:layout_width="#dimen/_30dp"
android:layout_height="#dimen/_30dp"
android:layout_gravity="right"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="#dimen/_10dp"
android:layout_marginRight="#dimen/_20dp"
android:layout_marginBottom="#dimen/_30dp"
android:background="#drawable/circular_cross_button" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_40dp"
android:background="#color/app_grey"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/product_details_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white">
<TextView
android:id="#+id/pick_your_option_label"
style="#style/subheading_manrope_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/_15dp"
android:layout_marginTop="#dimen/_15dp"
android:layout_marginBottom="#dimen/_10dp"
android:text="#string/pick_your_option"
android:textColor="#color/product_name_lite_black_color"
android:textSize="#dimen/_18dp"
android:visibility="gone" />
<View
android:id="#+id/line1"
android:layout_width="match_parent"
android:layout_height="#dimen/_1dp"
android:layout_below="#id/pick_your_option_label"
android:layout_marginLeft="#dimen/_15dp"
android:layout_marginTop="#dimen/_10dp"
android:layout_marginRight="#dimen/_15dp"
android:layout_marginBottom="#dimen/_15dp"
android:background="#color/line_color"
android:visibility="invisible" />
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/view_pager"
android:layout_width="#dimen/_136dp"
android:layout_height="#dimen/_136dp"
android:layout_below="#id/line1"
android:layout_marginLeft="#dimen/_16dp"
android:layout_marginTop="#dimen/_12dp"
android:layout_marginRight="#dimen/_12dp"
android:layout_marginBottom="#dimen/_8dp"
android:background="#drawable/grey_border_rounder_rectangle_8dp"
android:padding="#dimen/_1dp"
android:transitionName="#string/image" />
<LinearLayout
android:id="#+id/pager_dots"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/view_pager"
android:layout_gravity="center"
android:layout_marginLeft="#dimen/_16dp"
android:layout_marginBottom="#dimen/_15dp"
android:background="#android:color/transparent"
android:orientation="horizontal" />
<ImageView
android:id="#+id/product_image"
android:layout_width="#dimen/_120dp"
android:layout_height="#dimen/_120dp"
android:layout_marginLeft="#dimen/_10dp"
android:layout_marginRight="#dimen/_8dp"
android:layout_marginBottom="#dimen/_15dp"
android:transitionName="#string/image"
android:visibility="gone" />
<ImageView
android:id="#+id/elite_image"
android:layout_width="#dimen/_16dp"
android:layout_height="#dimen/_16dp"
android:layout_below="#id/line1"
android:layout_marginLeft="#dimen/_15dp"
android:visibility="gone"
app:srcCompat="#drawable/elite_icon" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
<TextView
android:id="#+id/product_name"
style="#style/body_manrope_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/line1"
android:layout_marginTop="#dimen/_12dp"
android:layout_marginRight="#dimen/_10dp"
android:layout_toRightOf="#id/view_pager"
android:ellipsize="end"
android:maxLines="2"
android:textColor="#color/product_name_lite_black_color" />
<View
android:id="#+id/view"
android:layout_width="1dp"
android:layout_toRightOf="#id/product_name"
android:layout_marginTop="#dimen/_12dp"
android:layout_marginLeft="#dimen/_3dp"
android:background="#color/divider_grey"
android:layout_height="#dimen/_35dp"/>
<TextView
style="#style/icon"
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_12dp"
android:layout_gravity="center"
android:layout_toRightOf="#+id/view"
android:layout_marginLeft="#dimen/_3dp"
android:layout_marginRight="#dimen/_5dp"
android:background="?selectableItemBackground"
android:gravity="center"
android:text="#string/camera_icon_id"
android:textSize="#dimen/_24dp"
android:textStyle="bold" />
<TextView
android:id="#+id/try_on"
style="#style/subheading_manrope_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_3dp"
android:layout_toRightOf="#id/view"
android:layout_below="#+id/icon"
android:textColor="#color/add_to_cart_violet" />
<TextView
android:id="#+id/price"
style="#style/subheading_manrope_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/product_name"
android:layout_marginTop="#dimen/_8dp"
android:layout_toRightOf="#id/view_pager"
android:textColor="#color/product_name_lite_black_color" />
<TextView
android:id="#+id/offer_price"
style="#style/subheading_manrope_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/product_name"
android:layout_marginLeft="#dimen/_4dp"
android:layout_marginTop="#dimen/_8dp"
android:layout_toRightOf="#id/price"
android:textColor="#color/product_mrp_lite_gray_color" />
<TextView
android:id="#+id/save_offer"
style="#style/caption_manrope_medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/product_name"
android:layout_marginLeft="#dimen/_4dp"
android:layout_marginTop="#dimen/_10dp"
android:layout_toRightOf="#id/offer_price"
android:textColor="#color/product_offer_price_color"
android:textSize="#dimen/_13dp"
android:visibility="gone" />
<TextView
android:id="#+id/offer_percantage"
style="#style/caption_manrope_medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/product_name"
android:layout_marginLeft="#dimen/_2dp"
android:layout_marginTop="#dimen/_10dp"
android:layout_toRightOf="#id/save_offer"
android:textColor="#color/product_offer_price_color"
android:textSize="#dimen/_13dp" />
<include
layout="#layout/new_rating_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/price"
android:layout_marginTop="#dimen/_8dp"
android:layout_toRightOf="#id/view_pager" />
<TextView
android:id="#+id/product_qty"
style="#style/caption_manrope_medium2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/new_rating_layout"
android:layout_marginLeft="#dimen/_12dp"
android:layout_marginTop="#dimen/_11dp"
android:layout_toRightOf="#id/view_pager"
android:gravity="center_vertical"
android:text="20ml"
android:textColor="#color/ash_gray"
android:textSize="#dimen/_10dp" />
<HorizontalScrollView
android:layout_below="#+id/product_qty"
android:layout_toRightOf="#id/view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_6dp"
android:layout_marginLeft="#dimen/_12dp"
android:scrollbars="none">
<com.google.android.material.chip.ChipGroup
android:id="#+id/chip_group"
app:singleLine="true"
app:singleSelection="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</HorizontalScrollView>
<View
android:id="#+id/line2"
android:layout_width="match_parent"
android:layout_height="#dimen/_1dp"
android:layout_below="#id/view_pager"
android:layout_marginLeft="#dimen/_15dp"
android:layout_marginTop="#dimen/_10dp"
android:layout_marginRight="#dimen/_15dp"
android:layout_marginBottom="#dimen/_10dp"
android:background="#color/line_color"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/product_details_layout"
android:layout_marginTop="#dimen/_8dp"
android:background="#color/white">
<TextView
android:id="#+id/shades_label"
style="#style/body_manrope_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/_2dp"
android:layout_marginTop="#dimen/_8dp"
android:layout_marginBottom="#dimen/_5dp"
android:layout_toRightOf="#+id/shade"
android:textColor="#color/dark_gray_color"
android:textStyle="bold"
android:visibility="gone" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/variant_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:layout_below="#+id/shade"
/>
</RelativeLayout>
</RelativeLayout>
<include
layout="#layout/variant_pop_up_bottom_bar_layout"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

Text is not correctly displaying in a TextView

I'm making a design in android using simple LinearLayout I create a TextView inside CardView when I enter long text inside TextView it hides some of the text, why this is happening? Check below image
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/universal_padding"> <!-- 8dp -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical">
<ImageView
android:id="#+id/ivCommentProfilePic"
android:layout_width="#dimen/card_profile_pic_width_height"
android:layout_height="#dimen/card_profile_pic_width_height"
app:srcCompat="#drawable/circular_photo" />
<ImageView
android:id="#+id/ivCommentUserBadge"
android:layout_width="#dimen/badge_width_height"
android:layout_height="#dimen/badge_width_height"
android:layout_marginTop="10dp"
android:layout_marginLeft="-10dp"
android:layout_marginStart="-10dp"
app:srcCompat="#drawable/shap_circle_badge" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/tvCommentUserFullName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textStyle="bold"
android:textColor="#color/colorPrimaryText"
android:text="Azeem Haider" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorSecondaryText"
android:text=" - 2d"/>
</LinearLayout>
<TextView
android:id="#+id/tvCommentText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/colorSecondaryText"
android:text="This is a comment for testing purpose This is a comment for testing purpose This is a comment for testing purpose"
/>
</LinearLayout>
</LinearLayout>
Try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<ImageView
android:id="#+id/ivCommentProfilePic"
android:layout_width="96dp"
android:layout_height="96dp"
app:srcCompat="#drawable/kid" />
<ImageView
android:id="#+id/ivCommentUserBadge"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="-10dp"
android:layout_marginStart="-10dp"
android:layout_marginTop="10dp"
app:srcCompat="#drawable/ic_online" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="8dp"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/tvCommentUserFullName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Azeem Haider"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" - 2d" />
</LinearLayout>
<TextView
android:id="#+id/tvCommentText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is a comment for testing purpose This is a comment for testing purpose This is a comment for testing purpose" />
</LinearLayout>
</LinearLayout>
OUTPUT

android fragment replace fiil_parent with frame layout

according to picture when i replace my fragment into FrameLayout the the size is not fit. for example my button in page is under the main layout object
activity_main layout code
<?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:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
android:orientation="vertical"
tools:context="com.teskaco.bbpos.Activities.MainActivities.MainActivity">
<com.alirezaafkar.toolbar.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:paddingTop="#dimen/app_bar_top_padding"
app:direction="rtl"
app:font="#string/font_path"
app:navigationIcon="#drawable/m_e_n_u"
app:optionsMenu="#menu/main_menu">
<com.teskaco.bbpos.CustumView.CustomTextView
android:id="#+id/main_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/psp_name"
android:textColor="#color/colorControlNormal"
android:textSize="#dimen/small_text_size" />
</com.alirezaafkar.toolbar.Toolbar>
<FrameLayout
android:id="#+id/main_fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<include
android:id="#+id/buttonPanel"
layout="#layout/main_top_bar" />
</LinearLayout>
my fragment layout xml code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/fragment_pay"
tools:context="com.teskaco.bbpos.Activities.MainActivities.PayBillFragment">
<com.teskaco.bbpos.CustumView.CustomButton
android:id="#+id/send_button"
style="#style/LightRaiseColorButtonRippleStyle"
android:layout_width="#dimen/_300sdp"
android:layout_height="#dimen/button_height"
android:layout_gravity="center"
android:layout_marginTop="#dimen/_4sdp"
android:gravity="center"
android:text="#string/send_button"
android:textColor="#color/disable_button"
android:textSize="#dimen/button_text_size" />
<LinearLayout
android:orientation="vertical"
android:gravity="center|top"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/_6sdp"
android:background="#color/white">
<RelativeLayout
android:id="#+id/skech_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:background="#color/white">
<ImageView
android:id="#+id/skech_image"
android:layout_width="#dimen/_90sdp"
android:layout_height="#dimen/_101sdp"
android:layout_centerHorizontal="true"
android:src="#drawable/ghabz" />
<com.teskaco.bbpos.CustumView.CustomTextView
android:id="#+id/ghabz_textview"
android:layout_width="#dimen/_250sdp"
android:layout_height="wrap_content"
android:layout_below="#+id/skech_image"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/_21sdp"
android:gravity="center"
android:text="#string/bill_text"
android:textSize="#dimen/mediume_text_size" />
</RelativeLayout>
<LinearLayout
android:id="#+id/name_layout"
android:layout_width="#dimen/_250sdp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_8sdp"
android:background="#drawable/raduis_bg_edit_text"
android:orientation="horizontal">
<com.teskaco.bbpos.CustumView.CustomTextInputLayout
android:id="#+id/shenase_text_input_layout"
android:layout_width="#dimen/_210sdp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_5sdp"
android:theme="#style/TextLabel">
<com.teskaco.bbpos.CustumView.CustomEditText
android:id="#+id/id_bill"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="#dimen/_6sdp"
android:layout_marginRight="#dimen/_6sdp"
android:layout_marginTop="#dimen/_4sdp"
android:background="#null"
android:gravity="right"
android:hint="#string/id_Bill_text"
android:inputType="number"
android:paddingBottom="#dimen/_4sdp"
android:textColor="#color/green_blue"
android:textSize="#dimen/defult_text_size" />
</com.teskaco.bbpos.CustumView.CustomTextInputLayout>
<android.support.v7.widget.AppCompatImageView
android:layout_width="#dimen/_16sdp"
android:layout_height="#dimen/_12sdp"
android:layout_gravity="center"
android:layout_marginLeft="#dimen/_5sdp"
android:background="#drawable/user_id" />
</LinearLayout>
<LinearLayout
android:id="#+id/name_layout1"
android:layout_width="#dimen/_250sdp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_8sdp"
android:background="#drawable/raduis_bg_edit_text"
android:orientation="horizontal">
<com.teskaco.bbpos.CustumView.CustomTextInputLayout
android:id="#+id/payment_text_input_layout"
android:layout_width="#dimen/_210sdp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_5sdp"
android:theme="#style/TextLabel">
<com.teskaco.bbpos.CustumView.CustomEditText
android:id="#+id/id_payment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="#dimen/_6sdp"
android:layout_marginRight="#dimen/_6sdp"
android:layout_marginTop="#dimen/_4sdp"
android:background="#null"
android:gravity="right"
android:hint="#string/id_payment_text"
android:inputType="number"
android:paddingBottom="#dimen/_4sdp"
android:textColor="#color/green_blue"
android:textSize="#dimen/defult_text_size" />
</com.teskaco.bbpos.CustumView.CustomTextInputLayout>
<android.support.v7.widget.AppCompatImageView
android:layout_width="#dimen/_16sdp"
android:layout_height="#dimen/_12sdp"
android:layout_gravity="center"
android:layout_marginLeft="#dimen/_5sdp"
android:background="#drawable/user_id" />
</LinearLayout>
<com.teskaco.bbpos.CustumView.CustomButton
android:id="#+id/barcode_reader"
style="#style/GrayRaiseColorButtonRippleStyle"
android:layout_width="#dimen/_250sdp"
android:layout_height="#dimen/button_height"
android:layout_gravity="center"
android:layout_marginTop="#dimen/_24sdp"
android:gravity="center"
android:text="#string/barcode_reader_text"
android:textColor="#color/disable_button"
android:textSize="#dimen/button_text_size" />
</LinearLayout>
</LinearLayout>
replace code
fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.main_fragment, PayBillFragment.newInstance()).addToBackStack("PayBill").commit();
You have to use Parent Layout as RelativeLayout and use RelativeLayout property.
<com.alirezaafkar.toolbar.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:paddingTop="#dimen/app_bar_top_padding"
app:direction="rtl"
app:font="#string/font_path"
app:navigationIcon="#drawable/m_e_n_u"
app:optionsMenu="#menu/main_menu">
<com.teskaco.bbpos.CustumView.CustomTextView
android:id="#+id/main_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/psp_name"
android:textColor="#color/colorControlNormal"
android:textSize="#dimen/small_text_size" />
</com.alirezaafkar.toolbar.Toolbar>
<FrameLayout
android:id="#+id/main_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/buttonPanel" />
<include
android:id="#+id/buttonPanel"
layout="#layout/tab_bottom_menus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>

RecyclerView adds marginBottom to its item

I have a RecyclerView that automatically adds a marginBottom to its childrens.
I already tried to put zero margins in XML and set 0 marginBottom programatically.
Android set these margins afeter onBindView of Adapter.
Its Like you can see in the image.
EDIT: Thats the XML file
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/message_processo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#fff"
app:cardCornerRadius="5dp"
android:elevation="2dp"
android:orientation="vertical"
app:cardBackgroundColor="#color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<br.com.isilist.android.view.widget.SquareImageView
android:id="#+id/iv_product_image"
android:src="#drawable/default_product_open_screen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:adjustViewBounds="true"/>
<View
android:layout_below="#+id/iv_product_image"
android:layout_above="#+id/container_bottom"
android:id="#+id/middle_separator"
android:layout_width="match_parent"
android:layout_height="1px"/>
<RelativeLayout
android:layout_below="#+id/iv_product_image"
android:id="#+id/container_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:paddingLeft="5dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_name"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:textSize="16sp"
android:text="Teste"
android:layout_marginBottom="#dimen/pad_5dp"
android:textColor="#color/dark_gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="4dp"
android:id="#+id/rl_sale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/red_button">
<TextView
android:textSize="12sp"
android:textColor="#fff"
android:layout_margin="3dp"
android:text="#string/sale"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<TextView
android:id="#+id/tv_unit_price"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:textSize="13sp"
android:layout_marginBottom="#dimen/pad_5dp"
android:textColor="#888"
android:text="Teste"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/rl_bottom_layout_list_product">
<LinearLayout
android:id="#+id/ll_info_quantity_price"
android:layout_centerVertical="true"
android:orientation="vertical"
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_marginLeft="8dp"
android:layout_marginStart="#dimen/pad_8dp"
android:layout_marginRight="#dimen/pad_8dp"
android:layout_marginEnd="#dimen/pad_8dp"
android:background="#888"
android:layout_width="match_parent"
android:layout_height="1px"/>
<TextView
android:id="#+id/tv_item_quantity"
android:textSize="13sp"
android:textColor="#888"
android:text="Quantidade: 12"
android:layout_marginTop="#dimen/pad_4dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:textSize="13sp"
android:textColor="#color/primary_color"
android:text="R$"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/tv_item_total_price"
android:textSize="#dimen/txt_18sp"
android:textColor="#color/primary_color"
android:text="148.99"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_marginBottom="-30dp"
android:layout_alignBottom="#+id/middle_separator"
android:id="#+id/ll_add_remove_item"
android:orientation="horizontal"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_toLeftOf="#+id/container_add_quantity"
android:layout_toStartOf="#+id/container_add_quantity"
android:elevation="3dp"
android:layout_margin="#dimen/pad_16dp"
android:id="#+id/container_deduct_quantity"
android:background="#drawable/circle_background_orange_white_stroke"
android:layout_width="#dimen/pad_35dp"
android:layout_height="#dimen/pad_35dp">
<ImageView
android:src="#drawable/ic_minus_white_48dp"
android:layout_centerInParent="true"
android:layout_width="#dimen/pad_30dp"
android:layout_height="#dimen/pad_30dp" />
</RelativeLayout>
<RelativeLayout
android:elevation="3dp"
android:layout_marginBottom="-30dp"
android:id="#+id/container_add_quantity"
android:layout_margin="#dimen/pad_16dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/circle_background_orange_white_stroke"
android:layout_width="#dimen/pad_35dp"
android:layout_height="#dimen/pad_35dp">
<ImageView
android:src="#drawable/ic_plus_white_48dp"
android:layout_centerInParent="true"
android:layout_width="#dimen/pad_30dp"
android:layout_height="#dimen/pad_30dp" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_badge"
android:layout_marginBottom="-12dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="#dimen/pad_16dp"
android:layout_alignBottom="#+id/middle_separator"
android:background="#drawable/circle_background_green"
android:layout_width="25dp"
android:layout_height="25dp">
<ImageView
android:id="#+id/iv_icon_badge_product"
android:src="#drawable/ic_check_white_48dp"
android:layout_centerInParent="true"
android:layout_width="20dp"
android:layout_height="20dp" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
There is a way to not allow RecyclerView to do that?
Two sources of this issue might be:
android:dividerHeight="" of your RecyclerView is too large. (In this case the last item doesn't have a bottom margin.)
Items themselves have their own bottom margin. (In this case all items have bottom margin.)

Picture not aligning top?

So in my program i have a layout implemented in which i want the image to alignTop of the parent. I used to exact same layout code for another activity (with minor changes) and it works perfectly but when using it in this activity it does not. My image still aligns to the center fo the view. Here is the layout 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/darkGray"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.intellidev.fuzionvapor.HomeDetails"
tools:showIn="#layout/activity_home_details">
<ImageView
android:id="#+id/homeDetailsActivityImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:scaleType="fitCenter" />
<TextView
android:id="#+id/homeDetailsActivityTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/homeDetailsActivityImage"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/homeDetailsActivityPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/homeDetailsActivityImage"
android:textColor="#color/fuzionRed"
android:textSize="20sp"
android:textStyle="bold" />
<View
android:id="#+id/homeDetailsActivityRuler"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_below="#+id/homeDetailsActivityTitle"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#color/white" />
<TextView
android:id="#+id/homeDetailsActivityDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/homeDetailsActivityRuler"
android:textColor="#color/white"
android:textSize="15sp" />
<LinearLayout
android:id="#+id/homeDetailsFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/homeDetailsActivityButton"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<fr.ganfra.materialspinner.MaterialSpinner
android:id="#+id/homeDetailsActivitySizeSpinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="1dp"
android:layout_weight="1"
app:ms_arrowColor="#color/fuzionRed"
app:ms_arrowSize="16dp"
app:ms_baseColor="#color/fuzionRed"
app:ms_enableFloatingLabel="true"
app:ms_floatingLabelColor="#color/fuzionRed"
app:ms_floatingLabelText="#string/sizeFloatingLabel"
app:ms_highlightColor="#color/fuzionRed"
app:ms_hintColor="#color/fuzionRed"
app:ms_hint="Size"
app:ms_multiline="false"
app:ms_thickness="1dp" />
<fr.ganfra.materialspinner.MaterialSpinner
android:id="#+id/homeDetailsActivityNicotineSpinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:layout_weight="1"
app:ms_arrowColor="#color/fuzionRed"
app:ms_arrowSize="16dp"
app:ms_baseColor="#color/fuzionRed"
app:ms_enableFloatingLabel="true"
app:ms_floatingLabelColor="#color/fuzionRed"
app:ms_floatingLabelText="#string/nicotineFloatingLabel"
app:ms_highlightColor="#color/fuzionRed"
app:ms_hintColor="#color/fuzionRed"
app:ms_multiline="false"
app:ms_hint="Nicotine"
app:ms_thickness="1dp" />
</LinearLayout>
<Button
android:id="#+id/homeDetailsActivityButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#color/fuzionRed"
android:text="Add To Cart"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="25sp"
android:textStyle="bold" />
</RelativeLayout>
change
<ImageView
android:id="#+id/homeDetailsActivityImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:scaleType="fitCenter" />
to
<ImageView
android:id="#+id/homeDetailsActivityImage"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:adjustViewBounds="true"
android:scaleType="fitStart" />

Categories

Resources