0

I want to draw a candlestick chart (500 itmes). In WPF, I can use 500 borders (System.Windows.Controls.Border) inside 1 scrollviewer. I also can change any item when it's needed.

How can I do the same in Xamarin.Android? Xamarin.Android doesn't contain the Border class.

David Watts
  • 2,249
  • 22
  • 33
Kirill
  • 1,412
  • 4
  • 21
  • 45
  • Normal way in android is to set nine-patch as background of the item ... or use CardView ... – Selvin Jun 22 '15 at 12:25

1 Answers1

0

you could use a ScrollView, containing a LinearLayout containing itself 500 times a simple <View> that has a size and a drawable stroke as background

something like

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        >
        <View
            android:layout_width="50dp"
            android:layout_height="100dp"
            android:background="@drawable/border_white"
            />
        <View
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/border_white"
            />

and in res/drawable, a file named border_white

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="2dip" android:color="@android:color/white" />
</shape>

but it'll be pretty slow I tell you (like on Windows, probably).

Benoit Jadinon
  • 1,082
  • 11
  • 21
  • How can I add border in View dynamically? What is the best way to create 500 rectangles in ScrollView (and change rectangle's size, when scrolling)? – Kirill Jun 22 '15 at 17:06
  • do you need to change the bars/views/borders width *when* scrolling ? why ? you can resize the Views, the rectangle will enlarge with it – Benoit Jadinon Jun 22 '15 at 17:21
  • Thank you very much! Yes, I need resize bars(views) width and height when scrolling dynamically. I will resize my views. – Kirill Jun 22 '15 at 20:38
  • How can I set border in View programmatically? I must create different views with different border colors. – Kirill Jun 22 '15 at 20:52
  • `view1.setBackground(getDrawable(R.drawable.border_white))` for hardcoded color borders – Benoit Jadinon Jun 23 '15 at 06:51
  • and if you've got many colors and need to create them dynamically, you could do this http://stackoverflow.com/questions/2145131/trying-to-draw-a-button-how-to-set-a-stroke-color-and-how-to-align-a-gradient#3663956 and pass the color to the constructor – Benoit Jadinon Jun 23 '15 at 06:58
  • super(s) - what is this? http://stackoverflow.com/questions/2145131/trying-to-draw-a-button-how-to-set-a-stroke-color-and-how-to-align-a-gradient#3663956 – Kirill Jun 23 '15 at 09:10
  • I should have explained, if you want to create a Shape with a Stroke from code instead of xml, you will have to subclass ShapeDrawable, because it doesn't provide a .setStroke() method. – Benoit Jadinon Jun 23 '15 at 14:13