0

I need to draw lines inside listView items, this line must show dependences between items. enter image description here I have read this, but i think it is difficult to draw lines by points in my case.And i think to use proggres bar, but it isn't a nice solution too What is the best practice to make this?for example, if i have tv1.weight=1, customview weight=3, tv.weight=1 how can i set widht of line?

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

<TextView
        android:layout_width="wrap_content"
        android:layout_height="2dp"
        android:text="New Text"
        android:id="@+id/textView"/>

<View
        android:layout_width="50dp"
        android:layout_height="1dp"
        android:background="@android:color/holo_blue_light" />

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/textView"/>

Community
  • 1
  • 1
Kostya Khuta
  • 1,798
  • 6
  • 25
  • 46

1 Answers1

1

First you need to make a custom adapter for Listview.

Then, for drawing line use :

<View
     android:layout_width="fill_parent"
     android:layout_height="2dp"
     android:background="#c0c0c0"/>

Now since the width of line is dependent on number inside listview item, you could easily set the layout_width of line inside getView() method of custom adapter.

You can set the height and width of a view in a LinearLayout like this

View someView = (View).findViewById(someId):
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) 
          someView .getLayoutParams();
params.height = 130;
someView .setLayoutParams(params);
vjdhama
  • 3,859
  • 4
  • 31
  • 46
  • But line will be on whole custom view? and when i have 3 items in my list_item.xml, it will be bad. I try somethink like this, watch my code – Kostya Khuta Apr 27 '14 at 14:11
  • for example, if i have tv1.weight=1, customview weight=3, tv.weight=1 how can i set widht of line? – Kostya Khuta Apr 27 '14 at 14:15
  • You will need to use a different `xml` that will define items inside a `listview` item. For more read this : http://www.vogella.com/tutorials/AndroidListView/article.html#adapterown – vjdhama Apr 27 '14 at 14:15
  • Don't add `layout_weight` to listview items. Also see updated answer. – vjdhama Apr 27 '14 at 14:23
  • ok, but how to be with another items in listview? Can you write xml code to item like on a pivture, next i have checked your answer – Kostya Khuta Apr 27 '14 at 14:41