Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to define Android GraphView in the layout file?
    text
    copied!<p><a href="http://www.jjoe64.com/p/graphview-library.html" rel="nofollow">GraphView</a> library for Android has a GraphView class, which is a View for creating graphs. This abstract class extends LinearLayout, so you can include a graph in layout by nesting LinearLayouts, like this:</p> <p>xml layout:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/mainLayout"&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Hello World!" /&gt; &lt;LinearLayout android:id="@+id/subLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>MainActivity.java:</p> <pre><code>public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); GraphViewData[] data = new GraphViewData[num]; double v = 0; for (int i = 0; i &lt; 10; i++) { v += 0.1; data[i] = new GraphViewData(i, Math.sin(v)); } GraphViewSeries seriesSin = new GraphViewSeries("Sinus", null, data); GraphView graphView = new LineGraphView(this, "DemoGraphView"); graphView.addSeries(seriesSin); graphView.setViewPort(2, 10); LinearLayout layout = (LinearLayout) findViewById(R.id.subLayout); layout.addView(graphView); } } </code></pre> <p>I nest LinearLayouts now but maybe there is a better way to include a graph in the layout file, eg. just like you place TextView or Button views?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload