创建一个带点的线来绘制“总线路径”

时间:2014-01-19 12:15:17

标签: android listview textview line point

我试图创建这样的东西:http://s28.postimg.org/a8zi7d4rx/Stop.jpg 我最初的想法是在右侧创建CanvasImage和X textviews。然后用Canvas绘制一些点。 现在我被困在了开始的时候;我无法动态添加2个textview,第一个低于1。 这是我的代码和结果的屏幕截图。 我该怎么办?

有人知道是否有完整的例子吗?

谢谢!

public class MainActivity extends Activity {
final int N = 10; // total number of textviews to add

final TextView[] myTextViews = new TextView[N]; // create an empty array;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main); 
    RelativeLayout l = (RelativeLayout) findViewById(R.id.lLayout);

    //fist txtview
    final TextView rowTextView1 = new TextView(this);
    rowTextView1.setText("This is the first row");
    RelativeLayout.LayoutParams p1 = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, 
            RelativeLayout.LayoutParams.WRAP_CONTENT);

    p1.addRule(RelativeLayout.RIGHT_OF, findViewById(R.id.imageView1).getId());
    l.refreshDrawableState();
    l.addView(rowTextView1,p1);
    l.requestLayout();
    myTextViews[0] = rowTextView1;


    for (int i = 1; i < N; i++) {
        final TextView rowTextView = new TextView(this);

        rowTextView.setText("This is row #" + i);

        RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, 
                RelativeLayout.LayoutParams.WRAP_CONTENT);

        p.addRule(RelativeLayout.RIGHT_OF, findViewById(R.id.imageView1).getId());
        //p.addRule(RelativeLayout.ALIGN_BOTTOM, myTextViews[i-1].getId());
        p.addRule(RelativeLayout.BELOW, rowTextView1.getId());

        p.setMargins(10, 10, 10, 10);
        l.addView(rowTextView, p);
        l.refreshDrawableState();

        myTextViews[i] = rowTextView;
    }


}

}

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<RelativeLayout
    android:id="@+id/lLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="#AEEEEE"
     >

    <ImageView
       android:id="@+id/imageView1"
       android:layout_width="10dp"
       android:layout_height="fill_parent"
       android:background="#000000"
       android:contentDescription="Base" />

</RelativeLayout>

,结果在这里:http://s18.postimg.org/e1z3yvlpl/Result.png

0 个答案:

没有答案