I am trying to create a bar chart inside a fragment, but the chart height is much smaller than expected. Also, changing the layout height to match_parent, fill_parent or wrap_content doesn't affect, but when the height is set to a number, it works properly, however that is not the solution that I want. What is the problem?
Here is the app image

post your xml
Below, there is the fragment xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity$PlaceholderFragment">
<com.github.mikephil.charting.charts.BarChart
android:id="@+id/barchart"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Below there is the activity xml
<android.support.design.widget.CoordinatorLayout
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:id="@+id/main_content"
android:layout_width="match_parent" android:layout_height="fill_parent"
android:fitsSystemWindows="true" tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout android:id="@+id/appbar"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways">
<Spinner android:id="@+id/spinner" app:popupTheme="@style/AppTheme.PopupOverlay"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView android:id="@+id/container"
android:layout_width="match_parent" android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
What happens if you change the NestedScrollView to a framelayout?
It crashes the app
Here is the logcat
10-26 15:33:02.945 19980-19980/com.example.pertence.myapplication8 E/AndroidRuntime:
FATAL EXCEPTION: main
10-26 15:33:02.945 19980-19980/com.example.pertence.myapplication8 E/AndroidRuntime:
Process: com.example.pertence.myapplication8, PID: 19980
10-26 15:33:02.945 19980-19980/com.example.pertence.myapplication8 E/AndroidRuntime:
android.view.InflateException: Binary XML file line #1: Error inflating class SrollView
@PhilJay ,why this issue closed?BarChart in NestedScrollView still have this problem.
Hi @PhilJay, is there any solution/clean workaround to this problem yet? I'm having the same issue with my NestedScrollView.
try android:fillViewport="true" in your scroll view.
Refer here
I solved my problem
Thank you @alyleite, you are right! It works.
I needed to create a <View height=400dp /> with <BarChart /> in a LinearLayout just to give it height :-/
this issue is still persisting
why should we give a fixed height for barchart always ?
Most helpful comment
try android:fillViewport="true" in your scroll view.
Refer here
I solved my problem