Fill CardView inside screen area - android

In my android app, I am a fragment in which I want to display to CardViews. These both CardViews should fill entire screen area. The image which is shown inside the cardview element is very large image and the same should be shrinked to display inside cardview. I am not able to fill entire area of screen with following code and make cardview clickable.
<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="match_parent"
tools:context="com.myFirstApp.app1.cardviewFragment">
<!-- TODO: Update blank fragment layout -->
<!--<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal"
android:background="#android:color/holo_blue_bright" ></android.support.v7.widget.RecyclerView>-->
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp" android:background="#color/colorAccent">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/card_view1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="8dp"
android:layout_marginBottom="16dp">
<LinearLayout android:orientation="vertical"
android:id="#+id/display_card_view_linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/display_name1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="13sp"
android:text="#string/app_name"
android:textColor="#ffffff"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:background="#1976D2"/>
<ImageView
android:id="#+id/display_image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/action_settings"
android:scaleType="fitCenter" />
<TextView
android:id="#+id/display_information1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="13sp"
android:text="Card View Footer"
android:textColor="#ffffff"
android:layout_below="#+id/display_image1"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:background="#1976D2"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="8dp"
android:layout_marginBottom="16dp">
<LinearLayout android:orientation="vertical"
android:id="#+id/display_card_view_linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/display_name2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="13sp"
android:text="#string/app_name"
android:textColor="#ffffff"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:background="#1976D2"/>
<ImageView
android:id="#+id/display_image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/action_settings"
android:scaleType="fitCenter" />
<TextView
android:id="#+id/display_information2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="13sp"
android:text="Card View Footer"
android:textColor="#ffffff"
android:layout_below="#+id/display_image2"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:background="#1976D2"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</FrameLayout>
How I can make both CardView fill entire area and make them clickable?
Thanks in advance,
IamHuM

try put this in cardview:
android:layout_margin="0dp"
i not have idea if this work for you but in one of my apps it worked you can se the code here GitHub code in the settings activity layout, i use a full width cardview.

Related

Is there a way to pull out image view from its' container a little bit in Android?

I want to create a layout based on the following image,
as it is evidence I have a CardView that I show it with red lines and the card view is in a LinearLayout and I have an image in the card view in which I want to show a little bit of it in a linear layout.
I use the following code to create the layout,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="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/grayBack"
android:orientation="vertical"
tools:context=".activities_v2.customer_steps.CustomerStepOne">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/md_white_1000"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginEnd="#dimen/_10sdp"
android:layout_marginRight="#dimen/_10sdp"
android:textColor="#color/editText"
android:textSize="#dimen/_14ssp"
/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_20sdp"
android:layout_marginLeft="#dimen/_20sdp"
android:layout_marginTop="#dimen/_100sdp"
android:layout_marginEnd="#dimen/_20sdp"
android:layout_marginRight="#dimen/_20sdp"
android:layout_marginBottom="#dimen/_10sdp"
android:minHeight="#dimen/_50sdp"
card_view:cardCornerRadius="#dimen/_10sdp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="236dp"
android:layout_height="#dimen/_150sdp"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:src="#drawable/ic_illustration_02" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="#dimen/_10sdp"
android:textColor="#color/editText"
android:textSize="#dimen/_14ssp" />
</LinearLayout>
</android.support.v7.widget.CardView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/button_background_blue"
android:minWidth="#dimen/_150sdp"
android:textSize="#dimen/_14ssp" />
</LinearLayout>

white backgroud for png Image in android studio

I'm trying to show some png images on RecyclerView, the images has transparent background but it show white background when run on device !!.
I tried to add
android:background="#android:color/transparent"
to ImageView, but still white
I use Picasso to load the image on ImageView, like that
Picasso.get()
.load(newpath)
.into(itemView.imgMCat)
this the fragment which contain the RecyclerView
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="#drawable/meskback"
tools:context=".HomeFragment">
<!-- TODO: Update blank fragment layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10">
<Toolbar
android:id="#+id/toolbar"
android:background="#color/meskBlue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light"
tools:targetApi="lollipop">
<Button
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="right"
android:layout_margin="7dp"
android:id="#+id/mapiconbtn"
android:background="#drawable/mapicon"
/>
</Toolbar>
<LinearLayout
android:layout_weight="6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="10"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="#+id/mainActivityRelayout1"
android:paddingTop="10dp"
android:layout_weight="5">
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
tools:srcCompat="#drawable/logo"
android:id="#+id/logoimg"
android:contentDescription="#string/logoimgdes"
android:src="#drawable/logo"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="5"
android:weightSum="2">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:textSize="22sp"
android:layout_weight="1"
android:textStyle="bold"
android:gravity="center"
android:textColor="#color/meskBlue"
android:text="#string/welcome"
android:textAlignment="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center"
android:layout_marginTop="20dp"
android:text="#string/how_can_we_help_you"
android:textAlignment="center"/>
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/McatRecylceView"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
and this is the item_view.xml which contain the ImageView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="140dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imgMCat"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#android:color/transparent"
android:layout_centerInParent="true"
android:layout_marginTop="3dp" android:layout_marginStart="3dp"
android:layout_marginEnd="3dp" android:layout_marginBottom="3dp"/>
<TextView
android:text="TextView"
android:id="#+id/mcategoryTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/imgMCat"
android:textAlignment="center"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
this photo for device
I found the answer here the problem was from CardView
https://stackoverflow.com/a/45769769/2209611
I add these attribute and fix the problem
app:cardBackgroundColor="#android:color/transparent"
app:cardElevation="0dp"
try this
<android.support.v7.widget.CardView
android:scaleType="centerInside"
android:layout_width="34dp"
android:layout_height="34dp"
android:clipChildren="false"
android:clipToPadding="false"
android:elevation="12dp"
android:shape="ring"
app:cardCornerRadius="17dp">
<ImageView
android:id="#+id/avatar"
android:layout_width="49dp"
android:layout_height="49dp"
android:layout_marginLeft="-8dp"
android:layout_marginTop="-5dp"
android:src="#drawable/blank" />
</android.support.v7.widget.CardView>
the image loads without a problem, what you need to do is set the height and width to wrap content instead of having a fixed width and a match parent height, here's what you should do in the xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="80dp">
<ImageView
android:id="#+id/imgMCat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:layout_centerInParent="true"
android:layout_marginTop="3dp" android:layout_marginStart="3dp"
android:layout_marginEnd="3dp" android:layout_marginBottom="3dp"/>
<TextView
android:text="TextView"
android:id="#+id/mcategoryTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/imgMCat"
android:textAlignment="center"/>
</RelativeLayout>
by setting the main layout to the sizes u want and then setting the imageview to wrap the content of the png you will have solved your problem
however, i would suggest that u never use fixed sizes for any UI components ever due to the amount of different devices with different screen sizes, if you use a fixed dimension UI elements then it's bound to be ruined on 1 screen or the other

wrap_content leaving extra white space at bottom of screen for ViewPager

enter image description here
Wrap_content inside 2nd linearlayout leaving the extra white space at bottom of screen but if give hardcoded value it's working fine. any issue with wrap_content ? Here I am using this .xml on viewPager anyone have idea about this issue.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/white_noround">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/canceledPesananTgl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ABCDEFGHI"
android:textSize="14sp"
android:padding="10dp"
android:textStyle="bold"
android:textColor="#999999"
android:fontFamily="sans-serif-light"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="-15dp"
android:text="29 JAN 2016"
android:textSize="14sp"
android:padding="10dp"
android:textStyle="bold"
android:textColor="#999999"
android:id="#+id/canceledDate"
android:fontFamily="sans-serif-light"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="vertical"
android:visibility="visible"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/image_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".9"
android:orientation="vertical"
android:layout_marginLeft="10dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="#+id/canceled_dummuyImage1"
android:background="#drawable/imageview_border"
android:layout_gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:src="#drawable/empty_photo"/>
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:id="#+id/canceled_dummuyImage2"
android:background="#drawable/imageview_border"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:src="#drawable/empty_photo"/>
<LinearLayout
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_marginTop="20dp"
android:background="#drawable/imageview_border">
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:id="#+id/canceledImage"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:src="#drawable/empty_photo"/>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight=".4"
android:paddingBottom="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SONY Memory Card Playstation 2"
android:textSize="16sp"
android:id="#+id/productName"
android:fontFamily="sans-serif-light"
android:textColor="#333333"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:id="#+id/productStatus"
android:textSize="14dp"
android:text="Dalam pengiriman"
android:textStyle="normal"
android:fontFamily="sans-serif"
android:textColor="#f7931e"/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
The Problem is here. see this Parent LinearLayout.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight=".4"
android:paddingBottom="10dp">
In this You have used android:paddingBottom="10dp" so the child' element work fine but The Extra white Space is for it's parent layout to Solve your problem remove android:paddingBottom="10dp" line.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="vertical"
android:visibility="visible"
>
in the above linear layout instead of layout_height as 150dp try giving wrap_content
What I was doing with above .xml was to populate list of items using listView on ViewPager. So the above .xml is listItem .xml so we should always go with below code.This line worked for me android:layout_height="wrap_content".
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/white_noround"/>

ScrollView inside ViewPager does not scroll on Android 4.x

I have a problem that seems to only impact Android 4.x versions and may be also device specific (i.e. it does not exist on my Huawei G630#4.3, but do exists on a Samsung Ace2#4.4.4).
I have a ScrollView that contains a RelativeLayout that has 4 CardViews. Now on some 4.x devices, the scroll event simply does not happen when I try to scroll beginning from a card. If I touch the small padding between the cards or above the first card (and not between any two) and the device screen, I can scroll the content.
<?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"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="#dimen/activity_horizontal_margin">
<android.support.v7.widget.CardView
android:id="#+id/metricsContainerCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="5dp"
android:src="#drawable/metrics"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/metrics"
android:textSize="20sp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/projectCircleBackgroundShadow"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/warningsContainerCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="#id/metricsContainerCard"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="5dp"
android:src="#drawable/bug_color"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/warnings"
android:textSize="20sp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/projectCircleBackgroundShadow"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/topWarningsContainerCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/warningsContainerCard"
android:layout_marginTop="10dp"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="5dp"
android:src="#drawable/top_warnings"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/topWarnings"
android:textSize="20sp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/projectCircleBackgroundShadow"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/topCriticalItemsContainerCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/topWarningsContainerCard"
android:layout_marginTop="10dp"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="5dp"
android:src="#drawable/top_critical_items"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/topCriticalItems"
android:textSize="20sp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/projectCircleBackgroundShadow"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
There isn't any problem on Android 5.x and 6.x.
EDIT
It seems that problem is not exclusively related to CardView, as I have another layout, and it also does not scroll even when I drag the screen by the custom view:
<ScrollView
android:id="#+id/scrollView"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".projects.details.ProjectDetailsActivity_">
<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="vertical"
android:padding="#dimen/activity_horizontal_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/projectName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:ellipsize="none"
android:gravity="center_horizontal"
android:text="Project name"
android:textSize="24sp"/>
<c.f.q.a.projects.details.components.widgets.ProjectDetailWidget
android:id="#+id/projectDetailWidget"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"/>
</LinearLayout>
<LinearLayout
android:id="#+id/timelineWrapperLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/qualityTimelineCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/flipQualityTimelineButton"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:src="#drawable/flip_to_cost"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:lines="1"
android:text="#string/project_timeline_title"
android:textSize="16dp"/>
</LinearLayout>
<ProgressBar
android:id="#+id/projectQualityTimelineProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<com.github.mikephil.charting.charts.LineChart
android:id="#+id/projectQualityTimeline"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="16dp"
android:tag="#string/project_chart_tag"
android:visibility="gone"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/costTimelineCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:visibility="gone"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/flipCostTimelineButton"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:src="#drawable/flip_to_quality"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:lines="1"
android:text="#string/project_cost_timeline_title"
android:textSize="16dp"/>
</LinearLayout>
<ProgressBar
android:id="#+id/projectCostTimelineProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<com.github.mikephil.charting.charts.LineChart
android:id="#+id/projectCostTimeline"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="16dp"
android:tag="#string/project_chart_tag"
android:visibility="gone"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<android.support.v7.widget.CardView
android:id="#+id/vcsChangeCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/expandVcsChangeButton"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginRight="5dp"
android:src="#drawable/expand_chart"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:maxLines="2"
android:text="#string/project_vcschange_title"
android:textSize="16sp"/>
</LinearLayout>
<ProgressBar
android:id="#+id/vcsChangeProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<com.github.mikephil.charting.charts.BarChart
android:id="#+id/projectVcsChange"
android:layout_width="match_parent"
android:layout_height="175dp"
android:layout_marginTop="16dp"
android:tag="#string/project_chart_tag"
android:visibility="gone"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/dtnosChangeCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/expandDtnosChangeButton"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginRight="5dp"
android:src="#drawable/expand_chart"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:maxLines="2"
android:text="#string/project_systemchange_title"
android:textSize="16sp"/>
</LinearLayout>
<ProgressBar
android:id="#+id/dtnosChangeProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<com.github.mikephil.charting.charts.BarChart
android:id="#+id/projectDtnosChange"
android:layout_width="match_parent"
android:layout_height="175dp"
android:layout_marginTop="16dp"
android:tag="#string/project_chart_tag"
android:visibility="gone"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:id="#+id/sensorNodeCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/expandSensornodeButton"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginRight="5dp"
android:src="#drawable/expand_chart"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:maxLines="2"
android:text="#string/project_sensornode_title"
android:textSize="16sp"/>
</LinearLayout>
<ProgressBar
android:id="#+id/sensorNodeProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<com.github.mikephil.charting.charts.RadarChart
android:id="#+id/sensorNodeChart"
android:layout_width="match_parent"
android:layout_height="175dp"
android:layout_marginTop="16dp"
android:tag="#string/project_chart_tag"
android:visibility="gone"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/aggregateNodeCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/expandAggregateButton"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginRight="5dp"
android:src="#drawable/expand_chart"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:maxLines="2"
android:text="#string/project_aggregatenode_title"
android:textSize="16sp"/>
</LinearLayout>
<ProgressBar
android:id="#+id/aggregateNodeProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<com.github.mikephil.charting.charts.RadarChart
android:id="#+id/aggregateNodeChart"
android:layout_width="match_parent"
android:layout_height="175dp"
android:layout_marginTop="16dp"
android:tag="#string/project_chart_tag"
android:visibility="gone"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</ScrollView>
I added the complete layout, and also here is an image for clarification (I marked the scrollable areas which I can drag):
EDIT2
Maybe it is also important that these layouts are Fragments inside a ViewPager. Is it possible that the ViewPager prevents the ScrollView (and any other views inside it) gaining the focus / handling the touch events? The code for my ViewPager is this:
<android.support.v4.view.ViewPager
android:id="#+id/projectPager"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
EDIT3
It seems the problem must be with ViewPager + (Nested)ScrollView (I tried to exchange the plain ScrollView with that, but without success). I created a dummy layout for my Fragment that only hosts a parent NestedScrollView, a LinearLayout and many big TextViews like this:
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollView"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".projects.details.ProjectDetailsActivity_">
<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="vertical"
android:padding="#dimen/activity_horizontal_margin">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:ellipsize="none"
android:gravity="center_horizontal"
android:text="Project name"
android:textSize="80sp"/>
... <!-- more TextViews come here -->
...and scrolling also doesn't work! Only at the very edge of the screen, as previously. I have no idea how can this happen...
Solved! I had exactly the same problem. You are probably using a PageTransformer ViewPager animation.
Disabling the custom page transformer for < Android 4.1 solved it:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
// there are problems with this on 4.0.3, probably also on 4.1
viewPager.setPageTransformer(true, new DepthPageTransformer());
}
Your post and research saved me a lot of time, thank you.
OTHER SOLUTION:
If you like your animation, you can also try changing your DepthPageTransformer to this: https://stackoverflow.com/a/28214802/1310343c
You are right, the 2 scrollable controls are competing with each other.
Use a NestedScrollView from the Support Library instead. It is designed to get around problems of this type.
It has many enhancements that lets it work with other scrollable controls, including the ViewPager, RecyclerView (as long as you call .setNestedScrolling(true)) and CoordinatorLayout.
Based on the above, I have been using this new class in all instances, and the scrolling within scrolling has been working perfectly. Our product is live with perfectly working NestedScrollView controls inside a ViewPager, some with embedded RecyclerView lists inside them as well.
For me this setup worked: I have a Coordinator layout which has below nested scrollview
<android.support.v4.widget.NestedScrollView
android:layout_marginTop="8dp"
android:fillViewport = "true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/content_app_bar_search_patient_module"/>
</android.support.v4.widget.NestedScrollView>
and <include layout="#layout/content_app_bar_search_patient_module"/>has a viewpager which has fragment which contains again a nested scrollview
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
.
.
.
</android.support.v4.widget.NestedScrollView>
Your ScrollView must have match_parent height and first child of scrollview ( LinearLayout ) must have wrap_content height

Prevent recycler view from taking up whole space

I am using RecyclerView in a fragment and have set it's height to wrap_content and with a button below it. But the problem is RecyclerView takes up the whole space and button is not visible. What is going wrong?
This is my xml file -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#fff"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/empty_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="17sp"
android:layout_marginTop="20dp"
android:visibility="gone"
android:text="You haven't added any names yet!"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/names_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"/>
<Button
android:id="#+id/add_name"
android:layout_width="203dp"
android:layout_height="wrap_content"
android:layout_below="#+id/recycler_view"
android:padding="15dp"
android:textColor="#F3F3F3"
android:textSize="17sp"/>
</LinearLayout>`
You should set weight to the RecyclerView and change the height to 0dp
<android.support.v7.widget.RecyclerView
android:id="#+id/names_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical"/>
Wrap the RecyclerView and the Button in a LinearLayout, than add
android:layout_height="0dp"
android:layout_weight="1"
to RecyclerView.
Your code should look like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:orientation="vertical">
<TextView
android:id="#+id/empty_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="You haven't added any names yet!"
android:textSize="17sp"
android:visibility="gone"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="false"
android:layout_alignParentEnd="true"
android:layout_below="#+id/empty_view"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/names_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical"/>
<Button
android:id="#+id/add_name"
android:layout_width="203dp"
android:layout_height="wrap_content"
android:layout_below="#+id/recycler_view"
android:padding="15dp"
android:textColor="#F3F3F3"
android:textSize="17sp"/>
</LinearLayout>
</LinearLayout>

Categories

Resources