ActivityStartup.java column_view.xml img_buttons_background.xml main.xml +
Android - Java Apache Config Windows Batch Linux Bash CSS Gradle HTML ini File iOS - Swift Java JavaScript JSON Format Kotlin LESS Markdown MySQL PHP Plain Text Properties File Rust Go Lang SCSS Swift XML
package jbrhmnqb.custom_views;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
public class ActivityStartup extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinkedHashMap<String, Long> values = new LinkedHashMap<String, Long>();
for (int y = 0; y < 40; y++) {
values.put(y + "دیتا", (long) (Math.random() * 1000));
}
setColumnChart(findViewById(R.id.chart), values);
}
private void setColumnChart(final View chart, final LinkedHashMap<String, Long> values) {
final LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
final ViewGroup columnContainer = (ViewGroup) chart.findViewById(R.id.columns);
float max = Float.MIN_VALUE;
float min = Float.MAX_VALUE;
Iterator<Entry<String, Long>> iterator = values.entrySet().iterator();
for (int i = 0; i < values.size(); i++) {
Entry<String, Long> next = iterator.next();
long value = next.getValue();
if (value > max) {
max = value;
}
if (value < min) {
min = value;
}
}
chart.measure(0, 0);
final float finalMax = max;
Iterator<Entry<String, Long>> iterator0 = values.entrySet().iterator();
for (int i = 0; i < values.size(); i++) {
Entry<String, Long> next = iterator0.next();
final long value = next.getValue();
String title = next.getKey();
final View column = inflater.inflate(R.layout.column_view, columnContainer, false);
final ImageView imgColomn = (ImageView) column.findViewById(R.id.imgColomn);
final TextView txtTitle = (TextView) column.findViewById(R.id.txtTitle);
txtTitle.setText(title);
columnContainer.addView(column);
new Handler().post(new Runnable() {
@Override
public void run() {
final int height = (int) (value * (chart.getHeight() - column.getHeight()) / finalMax);
columnContainer.removeView(column);
column.getLayoutParams().height = column.getHeight() + height;
imgColomn.setVisibility(View.VISIBLE);
columnContainer.addView(column);
}
});
}
}
}, 50);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearColumn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<ImageView
android:id="@+id/imgColomn"
android:layout_width="40dp"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/img_buttons_background"
android:visibility="gone" />
<TextView
android:id="@+id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:maxLines="1"
android:textColor="#000"
android:textSize="16sp" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#000" />
<corners android:radius="5dp" />
</shape>
</item>
<item
android:bottom="2dp"
android:right="1dp">
<shape>
<corners android:radius="5dp" />
<solid android:color="#0078D7" />
</shape>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:id="@+id/chart"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_margin="8dp" >
<LinearLayout
android:id="@+id/columns"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>