I am trying to write a code to plot a graph using aChartengine in an Android layout.I am successfully plot the graph but i am facing issue to align the Graph in the layout within a certain ViewGroup.
MyCode :
MainActivity.java
public class MainActivity extends ActionBarActivity {
List<double[]> xValues;
List<double[]> yValues;
List<double[]> yValues1;
GraphicalView view;
MultipleTemperatureChart multiple;
RelativeLayout rlt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
xValues = new ArrayList<double[]>();
yValues = new ArrayList<double[]>();
yValues1 = new ArrayList<double[]>();
rlt = (RelativeLayout) findViewById(R.id.rlt);
multiple = new MultipleTemperatureChart(this);
int[] data = {143,144,145,137,156,146,158,139,144,143};
double[] doubTime = new double[data.length];
double[] doubNote = new double[data.length];
double[] doubZero = new double[data.length];
for(int i=0;i<data.length;i++){
doubTime[i] = index;
doubNote[i] = data[i];
doubZero[i] = 0;
index++;
}
xValues.add(doubTime);
yValues.add(doubNote);
yValues1.add(doubZero);
view = multiple.execute(getApplicationContext(),xValues,yValues,yValues1);
view.setBackgroundColor(Color.YELLOW);
view.setLayoutParams(new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 400));
rlt.addView(view);
}
}
activity_main.xml
<RelativeLayout
xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="500dp"
android:orientation="vertical"
android:background="#33cc00"
android:id="@+id/rltParams">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/rlt"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/rlt"
android:background="#cc4455"
android:id="@+id/view"/>
</RelativeLayout>
So these are the codes and screenshots of my issue. I want to plot the graph within the Green RelativeLayout and also the Red View need to come below the graph layout.
Please suggest me some solution or technique to plot the graphs in the layout properly.
Aucun commentaire:
Enregistrer un commentaire