2017-09-18 13 views
0

親レイアウト全体(LinearLayoutConstraintLayoutの中にある)をカバーするHorizo​​ntalBarChartを作成しようとしています。Horizo​​ntalBarChart(MPAndroidChart)のすべての面(上下を含む)からパディングを削除するにはどうすればよいですか?

public static HorizontalBarChart horizontalBarChartSet(Context context, HorizontalBarChart mChart, float value) { 
    mChart.setDrawValueAboveBar(false); 
    mChart.getDescription().setEnabled(false); 
    mChart.setPinchZoom(false); 
    mChart.setDrawGridBackground(false); 

    //Vertical Axis 
    mChart.getXAxis().setEnabled(false); 

    //Horizontal Axis 1 
    YAxis yl = mChart.getAxisLeft(); 
    yl.setDrawAxisLine(false); 
    yl.setDrawGridLines(false); 
    yl.setDrawLabels(false); 
    yl.setAxisMinimum(0f); 
    yl.setAxisMaximum(100f); 

    //Horizontal Axis 2 
    YAxis yr = mChart.getAxisRight(); 
    yr.setDrawAxisLine(false); 
    yr.setDrawGridLines(false); 
    yr.setDrawLabels(false); 
    yr.setAxisMinimum(0f); 
    yr.setAxisMaximum(100f); 

    //Data 
    ArrayList<BarEntry> values = new ArrayList<BarEntry>(); 
    values.add(new BarEntry(0, value)); 

    BarDataSet set = new BarDataSet(values, ""); 

    ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>(); 
    dataSets.add(set); 

    BarData data = new BarData(dataSets); 
    mChart.setData(data); 

    //Highlight 
    data.setHighlightEnabled(false); 

    //Bar 
    data.setBarWidth(0.8f); 
    mChart.setFitBars(true); 

    //Legend 
    mChart.getLegend().setEnabled(false); 

    //General 
    mChart.setViewPortOffsets(0f,0f,0f,0f); 
    mChart.setExtraOffsets(0f, 0f, 0f, 0f); 

    //Animate 
    mChart.animateY(2500); 
    return mChart; 
} 

かかわらからパディングを削除setViewPortOffsets(0f,0f,0f,0f);を使用して左と右が、上部と下部とにいくつかのパディングがまだある私は、左右のパディングもデフォルト値に戻りバーをタッチすると: はここに私のコードです。ビューの

XML:

ここ
<android.support.constraint.ConstraintLayout 
    android:id="@+id/constraintLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintVertical_bias="0.0"> 

     <com.github.mikephil.charting.charts.HorizontalBarChart 
      android:id="@+id/percentage" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

    </LinearLayout> 
</android.support.constraint.ConstraintLayout> 

されているスクリーンショット:リストビューの食品で ルック

Before I touch the bar

After I touch the bar

+0

あなたはスクリーンショットを共有できます –

+0

あなたのレイアウトをデザインするのにネガティブパッドが使用できます –

+0

@MehulKabariaスクリーンショットを追加しました。私の編集を参照してください。 –

答えて

0

次の試してくださいすることができます

mChart.invalidate(); 

HorizontalBarChartをデータに追加した後。

+0

invalidate()メソッドを使用しようとしましたが、何も影響しません。 –

関連する問題