Nested Recyclerview of Images not clicked - android

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.

Related

layout_below not working with layout_centerVertical

I have been trying to use RelativeLayout in ScrollView to positioning two LinearLayouts, one to top and one to center. I've used layout_alignParentTop and layout_centerVertical. To prevent overlapping I've tried to use layout_below on second LinearLayout but it breaks layout_centerVertical and the second LinearLayout goes to top. How to do it? Thanks.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".activities.StartFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/trial_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="25dp"
android:layout_alignParentTop="true"
android:background="#drawable/trial_border"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="top"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_access_time_black_24dp" />
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical">
<TextView
android:id="#+id/trial_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left|center"
android:text="#string/trial_exp"
android:textColor="#color/darkGrey"
android:textSize="15sp" />
<TextView
android:id="#+id/trial_more"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right|center"
android:text="#string/trial_exp_more"
android:textColor="#color/darkGreen"
android:layout_marginRight="10dp"
android:textSize="13sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/trial_button"
android:layout_centerVertical="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/VImage"
android:layout_width="wrap_content"
android:layout_height="200sp"
android:src="#drawable/image_global" />
<TextView
android:id="#+id/VText"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center"
android:text="#string/protection_disabled"
android:textColor="#color/darkRed"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:gravity="center"
android:orientation="vertical">
<com.google.android.material.button.MaterialButton
android:id="#+id/start_vpn_button"
style="#style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="141dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/protect_me"
android:textColor="#color/white"
android:textStyle="bold"
app:backgroundTint="#color/green" />
<com.google.android.material.button.MaterialButton
android:id="#+id/stop_vpn_button"
style="#style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="141dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/unprotect_me"
android:textColor="#color/white"
android:textStyle="bold"
android:visibility="gone"
app:backgroundTint="#color/red" />
</LinearLayout>
<LinearLayout
android:id="#+id/r_button"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="50sp"
android:layout_marginRight="20dp"
android:background="#drawable/single_border"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
android:orientation="horizontal">
<ImageView
android:id="#+id/r_image"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="center"
android:src="#drawable/image_r_50" />
<TextView
android:id="#+id/r_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left|center"
android:text="#string/r_to"
android:textColor="#color/darkGrey"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>

RecyclerView Inside Recylerview, Inner RecyclerView Items does not displays completely on some devices

I have a requirement of screen with single scroll. Main Activity having one RecyclerView. This Row Item includes 2 recyclerview in which one is horizonatal and other is vertical. Whats the best approach to design this view please let me know.
Current issue which i am facing is with Inner Vertical RecyclerView items are not showing completely.
Your help is highly appreciated!
"activity-main.xml"
<?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="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:indeterminate="false"
android:minHeight="50dp"
android:minWidth="50dp"
android:padding="#dimen/dp_5"
android:progress="1"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_margin="#dimen/dp_5"
android:layout_weight="1"
android:visibility="visible" />
</LinearLayout>
"row_item.xml" of activity recyclerview
<?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="wrap_content"
android:background="#drawable/rounded_cornered_grey_stroke_background"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="start"
android:text="Title"
android:textColor="#color/sky_blue"
android:textSize="18sp"
android:textStyle="bold" />
<View
android:id="#+id/view_line"
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:background="#color/sky_blue" />
<TextView
android:id="#+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:gravity="bottom"
android:text="2018-08-30"
android:textColor="#color/sky_blue"
android:textSize="#dimen/sp_15"
android:textStyle="normal" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp"
android:background="#color/sky_blue" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
android:visibility="gone" />
<TextView
android:id="#+id/tv_no_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp"
android:background="#null"
android:padding="5dp"
android:text="No item found"
android:textColor="#color/dark_greish"
android:textSize="14sp"
android:textStyle="bold"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_margin="#dimen/dp_5"
android:layout_weight="1"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
"row_item.xml" of rv_list
<?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="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="start|center"
android:padding="5dp"
android:text="Name"
android:textColor="#color/dark_greish"
android:textSize="14sp"
android:textStyle="normal" />
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#android:color/white"
android:padding="5dp" />
<TextView
android:id="#+id/tv_value_one"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="start|center"
android:padding="5dp"
android:text="Value 1"
android:textColor="#color/dark_greish"
android:textSize="14sp"
android:textStyle="normal" />
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#android:color/white"
android:padding="5dp" />
<TextView
android:id="#+id/tv_value_two"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:gravity="start|center"
android:padding="5dp"
android:text="Value 2"
android:textColor="#color/dark_greish"
android:textSize="14sp"
android:textStyle="normal" />
</LinearLayout>
Try to use setRecycledViePool(viewPool) with your inner recyclerview in onCreateViewHolder method of outermost recylerview adapter. Just pass the reference of inner recyclerview view pool to this method parameter.

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>

3 equal height rows in a ScrollView

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>

not able to update adapter's button in a linearlayout

I have to implement the following view:
<ScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:overScrollMode="never" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/btnStart"
android:layout_width="match_parent"
android:layout_height="#dimen/default_button_height"
android:background="#drawable/rounded_alpha_button"
android:textColor="#color/labels"
android:textSize="#dimen/button_font_size"
android:text="#string/no_ora_inizio"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin" />
<LinearLayout
android:id="#+id/listTargets"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</ScrollView>
In the linearLayout listTargest I want to add a set of adapter, every adapters are defined as:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/alpha_white" >
<TextView
android:id="#+id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_toLeftOf="#+id/counterContainer"
android:ellipsize="end"
android:gravity="center_vertical"
android:textColor="#color/labels"
android:textSize="#dimen/label_font_size" />
<LinearLayout
android:id="#+id/counterContainer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="8dp"
android:gravity="center_vertical"
android:orientation="horizontal" >
<Button
android:id="#+id/btnSub"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="#drawable/circular_alpha_button"
android:gravity="center"
android:lineSpacingExtra="6dp"
android:text="-"
android:textColor="#color/labels"
android:textSize="#dimen/label_big_font_size" />
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:gravity="center"
android:text="0"
android:textColor="#color/labels"
android:textSize="#dimen/label_font_size" />
<Button
android:id="#+id/btnAdd"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="#drawable/circular_alpha_button"
android:gravity="center"
android:lineSpacingExtra="7dp"
android:text="+"
android:textColor="#color/labels"
android:textSize="#dimen/label_big_font_size" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray" />
</RelativeLayout>
the UI is not working property because when I tap on the buttons in the adapter the UI is not updated
Can you help me? Any Idea?
Regards

Categories

Resources