0

I'm using MPAndroidChart library to draw a half pie chart in a RecyclerView. this is my item layout:

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    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"
    android:elevation="3dp"
    card_view:cardCornerRadius="12dp"
    card_view:contentPadding="10dp"
    android:layout_marginTop="8dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/platforms_title_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:drawablePadding="5dp"
            android:fontFamily="@font/roboto"
            android:gravity="center_vertical"
            android:text="@string/platforms"
            android:textAllCaps="true"
            android:textColor="@color/colorTextStandard"
            android:textSize="20sp"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"/>

        <TextView
            android:id="@+id/platforms_count_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginTop="8dp"
            android:fontFamily="@font/roboto"
            tools:text="4"
            android:drawablePadding="5dp"
            android:drawableStart="@drawable/ic_menu_monitor"
            android:textColor="@color/colorTextStandard"
            android:textSize="14sp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"/>

        <com.github.mikephil.charting.charts.PieChart
            android:id="@+id/platforms_chart"
            android:layout_width="match_parent"
            android:layout_height="@dimen/platforms_card_height"
            android:layout_below="@id/platforms_title_txt"/>

    </RelativeLayout>

the result is that the piechart is being draw very small, I can't control it's size.

Any idea or example how can I have the PieChart with fixed size?

Thanks.

Sharas
  • 1,985
  • 3
  • 20
  • 43

3 Answers3

0

relativelayout.setLayoutParams(new ViewGroup.LayoutParams( constant_width, constant_height));

(or)

RelativeLayout layout = new RelativeLayout(this);
RelativeLayout.LayoutParams layoutParams = RelativeLayout.LayoutParams)layout.getLayoutParams();
layoutParams.height = dpToPx(YOUR_HEIGHT);
layoutParams.width = dpToPx(YOUR_WIDTH);
layout.setLayoutParams(layoutParams);

  • Thanks, but I tried that, and still the PieChart is either too small or invisible (the card layout height only wraps the textview) – Sharas Jun 27 '18 at 06:12
0
<com.github.mikephil.charting.charts.PieChart
            android:id="@+id/platforms_chart"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/platforms_title_txt"/>
Harshal Deshmukh
  • 1,787
  • 3
  • 14
  • 25
0

Found the problem...

When I tried to move the chart down to reduce the space it takes, the value I gave was too big.

I still have to give it a fix size and can't use match_parent, but I think i can live with that...

Sharas
  • 1,985
  • 3
  • 20
  • 43