Add RelativeLayout with buttons below RecyclerView - android

I need to add a RelativeLayout below my RecyclerView and was able to do so, except that the button under TOTAL(R.id.total_amount_tv) does not show:
I can easily scroll through the items and it doesn't affect my RelativeLayout. I just need the button to be visible.
<RelativeLayout 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="#android:color/white"
android:weightSum="1">
<android.support.v7.widget.RecyclerView
android:id="#+id/order_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
tools:context=".ShoppingCartActivity" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<TextView
android:id="#+id/total_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="#string/total"
android:textSize="20sp"
android:textStyle="bold|italic" />
<TextView
android:id="#+id/total_amount_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/total_tv"
android:textSize="20sp"
android:textStyle="bold|italic" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#+id/total_amount_tv"
android:layout_marginTop="51dp"
android:background="#color/accent"
android:onClick="onClickSendOrder"
android:text="#string/order_btn"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
</RelativeLayout>

You need to divide the screen in to two Parts one for showing the Recyclerview and other for RelativeLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical"
android:weightSum="10">
<android.support.v7.widget.RecyclerView
android:id="#+id/order_recycler"
android:layout_weight = "8.5"
android:layout_width="match_parent"
tools:context=".ShoppingCartActivity" />
<RelativeLayout
android:layout_weight = "1.5"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginRight="10dp">
<TextView
android:id="#+id/total_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="Total"
android:textSize="20sp"
android:textStyle="bold|italic" />
<TextView
android:id="#+id/total_amount_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/total_tv"
android:textSize="20sp"
android:text="Total Right"
android:textStyle="bold|italic" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/total_amount_tv"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:onClick="onClickSendOrder"
android:text="Button"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
This will produce the following results

android:layout_alignParentBottom="true"
This is the likely culprit. Both TextViews are aligned at the bottom of their parent RelativeLayout. This doesn't leave room for the Button.

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/downline_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/lin_result"
android:layout_marginTop="5dp" />
<LinearLayout
android:id="#+id/lin_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#f8ffffff"
android:orientation="vertical"
android:paddingBottom="10dp">
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginBottom="5dp"
android:background="#999898" />
<TextView
android:id="#+id/text_total_rupees"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="100"
android:textAppearance="#style/TextAppearance.AppCompat.Medium" />
</LinearLayout>
</RelativeLayout>

Related

How to put TextView below RecyclerView in NestedScrollView in android

I want to create a layout in which cart price and the total price will be displayed below the recycler view but when text view is placed below recycler view it gets invisible
I have searched on the internet about this but didn't find any solution
when text view is below the recycler view it gets invisible
Thanks in advance
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="10">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/cartRecyclerView"
android:layout_weight = "8.5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".ShoppingCartActivity" />
<RelativeLayout
android:layout_weight = "1.5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp">
<TextView
android:id="#+id/cartFragmentTextTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="Total"
android:textSize="20sp"
android:textStyle="bold|italic" />
<TextView
android:id="#+id/cartFragmentTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/total_tv"
android:textSize="20sp"
android:text="Total Right"
android:textStyle="bold|italic" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/total_amount_tv"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:onClick="onClickSendOrder"
android:text="Button"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
Try this
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/cartRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="8.5"
tools:context=".ShoppingCartActivity" />
</androidx.core.widget.NestedScrollView>
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/cartFragmentTextTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:text="Total"
android:textSize="20sp"
android:textStyle="bold|italic" />
<TextView
android:id="#+id/cartFragmentTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:text="Total Right"
android:textSize="20sp"
android:textStyle="bold|italic" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:onClick="onClickSendOrder"
android:text="Button"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
</RelativeLayout>
Can you try this?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/cartRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="8"
tools:listitem="#layout/tek_satir_playlist" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical"
>
<TextView
android:id="#+id/cartFragmentTextTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:text="Total"
android:textSize="20sp"
android:textStyle="bold|italic" />
<TextView
android:id="#+id/cartFragmentTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="224dp"
android:layout_marginRight="224dp"
android:text="Total Right"
android:textSize="20sp"
android:textStyle="bold|italic" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:onClick="onClickSendOrder"
android:text="Button"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
First of all, you can not use weight and weightSum attributes for relative layout.
As I understand from your code You do not need to use the nested scroll, try this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/cartRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/bottom_container"
tools:context=".ShoppingCartActivity" />
<RelativeLayout
android:id="#+id/bottom_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginRight="10dp">
<TextView
android:id="#+id/cartFragmentTextTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:text="Total"
android:textSize="20sp"
android:textStyle="bold|italic" />
<TextView
android:id="#+id/cartFragmentTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:text="Total Right"
android:textSize="20sp"
android:textStyle="bold|italic" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:onClick="onClickSendOrder"
android:text="Button"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
I change the first sub Layout in androidx.core.widget.NestedScrollView to ConstraintLayout too easily position your RelativeLayout in it.
bellow is the completed code, I hope it would help...
<androidx.core.widget.NestedScrollView 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="#android:color/white">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/cartRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#+id/footer"
tools:context=".ShoppingCartActivity" />
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1.5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cartRecyclerView">
<TextView
android:id="#+id/cartFragmentTextTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:text="Total"
android:textSize="20sp"
android:textStyle="bold|italic" />
<TextView
android:id="#+id/cartFragmentTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/total_tv"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:text="Total Right"
android:textSize="20sp"
android:textStyle="bold|italic" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/total_amount_tv"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:onClick="onClickSendOrder"
android:text="Button"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Try this code
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="#android:color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/cartRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"/>
<TextView
android:id="#+id/cartFragmentTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:margin_top="30dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:text="Total Cost"
android:textSize="20sp"
android:textStyle="bold|italic" />
<LinearLayout>
</androidx.core.widget.NestedScrollView>

Format issue placing two views side by side in RelativeLayout

I have two views side by side inside a relative layout. I want the format of both views to be like the one on the left ("Today's Special"). I've assigned both views the same attributes though they are different.
here is my xml.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="ExtraText">
<RelativeLayout
android:id="#+id/view_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/bg_row_background">
<ImageView
android:id="#+id/delete_icon"
android:layout_width="#dimen/ic_delete"
android:layout_height="#dimen/ic_delete"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/padd_10"
android:contentDescription="#string/deleteIcon"
android:src="#drawable/ic_delete_white_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/padd_10"
android:layout_toStartOf="#id/delete_icon"
android:text="#string/delete"
android:textColor="#fff"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/view_foreground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:padding="#dimen/padd_5">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="#dimen/ic_delete"
android:background="#color/description"
android:textColor="#color/item_name"
android:textSize="12sp" />
<TextView
android:id="#+id/namecat"
android:layout_width="wrap_content"
android:layout_height="#dimen/ic_delete"
android:layout_alignParentEnd="true"
android:layout_toEndOf="#id/name"
android:background="#color/description"
android:paddingStart="#dimen/padd_10"
android:textColor="#color/item_name"
android:textSize="12sp" />
</RelativeLayout>
</FrameLayout>
Thanks for your help.
Replace FrameLayout with LinearLayout and weightsum property
<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:orientation="horizontal"
android:weightSum="2"
tools:ignore="ExtraText">
<RelativeLayout
android:id="#+id/view_background"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="#978c8c">
<ImageView
android:id="#+id/delete_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_lock" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="#id/delete_icon"
android:text="#string/dummy_button"
android:textColor="#fff"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/view_foreground"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="#android:color/white">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:background="#color/colorAccent"
android:textColor="#color/colorPrimary"
android:textSize="12sp" />
<TextView
android:id="#+id/namecat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_toEndOf="#id/name"
android:background="#color/colorAccent"
android:textColor="#color/colorPrimaryDark"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>

Two LinearLayouts side by side, one with minimum-width

I got a RelativeLayout and inside there are two LinearLayouts side by side. Now I want that the right one has a minimum width of 125dp. So when the left LinearLayout gets too big, it should stop before the other LinearLayout and not push that one away.
How can I achieve this? This is my current approach:
Layout:
<?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:id="#+id/item_list_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<ImageButton
android:id="#+id/basket_item_list_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#android:color/transparent"
android:minWidth="50dp"
android:minHeight="50dp"
app:srcCompat="#drawable/ic_garbage"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_toRightOf="#+id/basket_item_list_delete"
android:layout_toEndOf="#+id/basket_item_list_delete">
<LinearLayout
android:id="#+id/basket_item_list_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:orientation="vertical">
<TextView
android:id="#+id/basket_item_list_itemname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:text="ItemName"
android:textColor="#color/generalText"
android:textSize="18sp" />
<TextView
android:id="#+id/basket_item_list_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:text="Options"/>
</LinearLayout>
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="125dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:orientation="vertical"
android:layout_toRightOf="#id/basket_item_list_description">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/basket_item_list_increment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/basket_item_list_count"
android:layout_toStartOf="#+id/basket_item_list_count"
android:minWidth="45dp"
android:minHeight="45dp"
android:text="+"
android:textSize="20sp"
android:textColor="#color/colorPrimary"
android:background="#android:color/transparent" />
<TextView
android:id="#+id/basket_item_list_count"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="false"
android:layout_alignParentRight="false"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/basket_item_list_decrement"
android:layout_toStartOf="#+id/basket_item_list_decrement"
android:gravity="center_horizontal"
android:text="nx"
android:textColor="#color/generalText"
android:textSize="14sp" />
<Button
android:id="#+id/basket_item_list_decrement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:minWidth="45dp"
android:minHeight="45dp"
android:text="–"
android:textSize="20sp"
android:textColor="#color/colorPrimary"
android:background="#android:color/transparent" />
</RelativeLayout>
<TextView
android:id="#+id/basket_item_list_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="50dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:text="1€"
android:gravity="right"
android:layout_gravity="right"
android:textColor="#color/generalText"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
I want to have it like this:
But this is what happens, when the left LinearLayout gets too big:
Try this
<?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/item_list_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<ImageButton
android:id="#+id/basket_item_list_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:background="#android:color/transparent"
android:minHeight="50dp"
android:minWidth="50dp"
app:srcCompat="#drawable/ic_menu_gallery" />
<LinearLayout
android:id="#+id/basket_item_list_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="#+id/basket_item_list_itemname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:text="ItemName"
android:textColor="#color/colorPrimary"
android:textSize="18sp" />
<TextView
android:id="#+id/basket_item_list_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:text="Options" />
</LinearLayout>
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:gravity="right"
android:minWidth="125dp"
android:orientation="vertical"
android:paddingBottom="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="#+id/basket_item_list_increment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:minHeight="45dp"
android:minWidth="45dp"
android:text="+"
android:textColor="#color/colorPrimary"
android:textSize="20sp" />
<TextView
android:id="#+id/basket_item_list_count"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="nx"
android:textColor="#color/colorPrimary"
android:textSize="14sp" />
<Button
android:id="#+id/basket_item_list_decrement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:minHeight="45dp"
android:minWidth="45dp"
android:text="–"
android:textColor="#color/colorPrimary"
android:textSize="20sp" />
</LinearLayout>
<TextView
android:id="#+id/basket_item_list_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="center"
android:minWidth="50dp"
android:text="1€"
android:textColor="#color/colorPrimary"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
Let try this ,
It will divide a screen Half and Half.
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".5"
android:orientation="vertical">
///Your views
</LinearLayout>
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".5"
android:orientation="vertical">
///Your views
</LinearLayout>
</LinearLayout>
If You want first Wrap another one take remaining width take this
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
///Your views
</LinearLayout>
<LinearLayout
android:id="#+id/priceLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
///Your views
</LinearLayout>
</LinearLayout>

The items in RecyclerView fit the width space irregularly

I have a RecycleView that loads review comments in a vertical LinearLayout that has layout_width attribute set to "match_parent". The adapter loads the items, but not as expected.
The first few items in my adapter do not fit the entire width space and they look visually wrong. But as I scroll down the list, it looks like the list refreshes itself and now the items are loaded fitting the entire width space.
I do not know how to best describe this problem as I have not found anything relevant concerning it. What do you think it is and how can I fix visually my RecyclerView?
enter image description here
enter image description here
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#2A2A2A">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/poster_image"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_width="150dp"
android:layout_height="230dp" />
<LinearLayout
android:layout_marginTop="40dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/release_date_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textStyle="italic"
android:textColor="#color/white"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/first_star"
android:backgroundTint="#color/colorAccent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_grade_white_18px"/>
<ImageView
android:id="#+id/second_star"
android:backgroundTint="#color/colorAccent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_grade_white_18px"/>
<ImageView
android:id="#+id/third_star"
android:backgroundTint="#color/colorAccent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_grade_white_18px"/>
<ImageView
android:id="#+id/forth_star"
android:backgroundTint="#color/colorAccent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_grade_white_18px"/>
<ImageView
android:id="#+id/fifth_star"
android:backgroundTint="#color/colorAccent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_grade_white_18px"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/vote_average_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:textColor="#color/white"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#EEFF41"
android:text="ADD"
android:textSize="18sp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginBottom="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textColor="#color/white"
android:text="Overview" />
<View
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#FF6F00" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/overview_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="#color/white"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="30dp"
android:layout_marginBottom="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textColor="#color/white"
android:text="Reviews"/>
<View
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#FF6F00" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:id="#+id/review_fragment_head"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginBottom="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textColor="#color/white"
android:text="Trailers"/>
<View
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#FF6F00" />
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>

Implementing ScrollView Android?

I've got one question. I designed layout for movie details and it looks like this:
Now, I want to add movie description when user scroll down (so this layout stays the same, but when user scrolls it will display movie description).
Current layout is wrapped in LinearLayout (vertical).
How could I implement that scroll ? I tried to add scroll view as parent but it stretches this layout down...
Here is code by now ...
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10">
<ImageView
android:id="#+id/iv_backdrop"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:scaleType="centerCrop" />
<LinearLayout
android:id="#+id/layout_favorite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-40dp"
android:gravity="right">
<RelativeLayout
android:layout_width="100dp"
android:layout_height="80dp"
android:layout_marginEnd="25dp">
<ImageView
android:id="#+id/iv_background_favorite"
android:layout_width="100dp"
android:layout_height="80dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:tint="#000000"
app:srcCompat="#drawable/ic_ellipse" />
<ImageView
android:id="#+id/iv_foreground_favorite"
android:layout_width="65dp"
android:layout_height="45dp"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
app:srcCompat="#drawable/ic_favorite_border_white_36px" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_short_desc"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="-20dp"
android:layout_weight="4">
<ImageView
android:id="#+id/iv_poster"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginStart="20dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:orientation="vertical">
<TextView
android:id="#+id/tv_title"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:textSize="19sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_tagline"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="8dp"
android:textSize="16sp"
android:textStyle="italic" />
<TextView
android:id="#+id/tv_movie_released"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="8dp"
android:text="12-12-2007(Released)"
android:textAlignment="viewStart"
android:textAllCaps="false"
android:textSize="16sp" />
<TextView
android:id="#+id/tv_movie_duration"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="8dp"
android:text="Duration - 90 min"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
<View
android:id="#+id/v_separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="20dp"
android:background="#android:color/darker_gray" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:weightSum="4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:src="#drawable/hexagon" />
<TextView
android:id="#+id/tv_vote_average"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:textColor="#ffffff"
android:textSize="16sp" />
<TextView
android:id="#+id/tv_number_votes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:textColor="#000000"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:adjustViewBounds="true"
android:src="#drawable/theatre" />
<TextView
android:id="#+id/tv_genre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:textColor="#000000"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:src="#drawable/circle_double_border" />
<TextView
android:id="#+id/tv_popularity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center_horizontal"
android:textColor="#ffffff"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:text="Popularity"
android:textColor="#000000"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:src="#drawable/circle_double_border" />
<TextView
android:id="#+id/tv_language"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:textColor="#ffffff"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:text="Language"
android:textColor="#000000"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
For Your Description only, simply use a NestedScrollView. Make sure that the height and width of NestedScrolllView are the ones that you originally used for your description TextView. Then Simply place the TextView in the NestedScrollView.
Read more about nestedScrollView here
https://developer.android.com/reference/android/support/v4/widget/NestedScrollView.html
http://www.devexchanges.info/2016/07/nested-scroll-views-in-android.html
Use something like this
<ScrollView> //Should be on top
<RelativeLayout> //Scroll View Contains only child view
<RelativeLayout>
//Paste your whatever so far created views.
</RelativeLayout>
<RelativeLayout>
//Place your Description view here
</RelativeLayout>
</RelativeLayout>
</ScrollView>

Categories

Resources