This is a view called HorizontalFlowChart for android application.You can use it easy to create a horizontal flow chart in you project.
- If you want to use the HorizontalFlowChart in your android application , you must copy two files
(HorizontalFlowChart.java,attrs.xml)
to you project. - Add the
namespace
in your layout file.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:horizontalflowchart="http://schemas.android.com/apk/res/com.example.horizontalflowchart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
</LinearLayout>
HorizontalFlowChart provide 15 user-defined attributes,including the loading rate,text color,text offset and etc.
circle_sum
: how many circles this HorizontalFlowChart hasbig_circle_radius
: the radius of the big circle in this HorizontalFlowChartsmall_circle_radius
: the radius of the small circle in this HorizontalFlowChartbig_line_width
: the length of each line between two circles- if you didn't set value for this attribute , HorizontalFlowChart will measure it automatic
big_line_height
: the height of each line between two circlessmall_line_height
: the height of the line which has Loaded between two circlesbig_color
: the color of the big circle and linesmall_color
: the color of the small circle and linehas_text
: whether this HorizontalFlowChart has texttext_color
: the color of the text in HorizontalFlowCharttext_size
: the size of the text in HorizontalFlowCharttext_gravity
: the gravity of the text in HorizontalFlowChartBOTTOM
CENTER
TOP
text_offset
: the offset of the text in HorizontalFlowCharttouch_circle_color
: the color of the circles when the user is touchingloading_rate
: the loading rate when this HorizontalFlowChart is loading,it must be anInteger
<com.example.horizontalflowchart.HorizontalFlowChartView
android:id="@+id/horizontalflowchart"
android:layout_width="match_parent"
android:layout_height="100dp"
android:padding="15dp"
horizontalflowchart:circle_sum="4"
horizontalflowchart:big_circle_radius="30dp"
horizontalflowchart:small_circle_radius="25dp"
horizontalflowchart:big_line_width="33dp"
horizontalflowchart:big_line_height="10dp"
horizontalflowchart:big_color="#c0c0c0"
horizontalflowchart:small_color="#789262"
horizontalflowchart:small_line_height="5dp"
horizontalflowchart:has_text="true"
horizontalflowchart:text_size="12sp"
horizontalflowchart:text_color="#424b50"
horizontalflowchart:text_offset="15dp"
horizontalflowchart:text_gravity="BOTTOM"
horizontalflowchart:touch_circle_color="#424b50"
horizontalflowchart:loading_rate="15"
/>
In .JAVA file,you can:
set the text of each circle by String[]
set the num of the circle which has Loaded last
set the rate of loading
set OnTouchCircleListener for callback
HorizontalFlowChartView horizontalflowchart =(HorizontalFlowChartView) findViewById(R.id.horizontalflowchart);
horizontalflowchart.setText(new String[]{"初始","开工","收工","回到基地"});
horizontalflowchart.setNowCircle(2);
horizontalflowchart.setLoadingRate(15);
horizontalflowchart.setOnTouchCircleListener(new OnTouchCircleListener() {
@Override
public void onTouchCircle(int mCircleNum) {
}
});
public interface OnTouchCircleListener {
public void onTouchCircle(int mCircleNum);//mCircleNum is the num of the circle the user has touched,from 0
}
Use in xml:
horizontalflowchart:touchable="true|false"
Use in java:
horizontalFlowChart.setTouchable(true|false);