2013-09-04 1 views

답변

-1

저는 AchartEngine을 사용하지 않고 동적으로 그런 것을 만듭니다. enter image description here

여기 샘플 자바 코드.

public class MainActivity extends Activity { 

private LinearLayout linear; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Random randomGenerator = new Random(); 
    for (int i = 0; i < 100; i++) { 
     linear = (LinearLayout) findViewById(R.id.linear); 
     LinearLayout lay = new LinearLayout(this); 
     LinearLayout lay1 = new LinearLayout(this); 
     TextView text = new TextView(this); 
     text.setText("ONES"); 
     text.setTextColor(Color.parseColor("#000000")); 
     text.setLayoutParams(new LinearLayout.LayoutParams(60, 40)); 

     TextView line = new TextView(this); 
     line.setBackgroundColor(Color.parseColor("#00FF00")); 
     line.setLayoutParams(new LinearLayout.LayoutParams(5, 90)); 

     TextView btn = new TextView(this); 
     int randomInt = randomGenerator.nextInt(100); 
     if (randomInt > 0 && randomInt <= 10) { 
      btn.setBackgroundColor(Color.parseColor("#FF1919")); 
     } else if (randomInt > 10 && randomInt <= 20) { 
      btn.setBackgroundColor(Color.parseColor("#C41300")); 
     } else if (randomInt > 20 && randomInt <= 30) { 
      btn.setBackgroundColor(Color.parseColor("#AB1100")); 
     } else if (randomInt > 30 && randomInt <= 40) { 
      btn.setBackgroundColor(Color.parseColor("#7A0C00")); 
     } else if (randomInt > 40 && randomInt <= 50) { 
      btn.setBackgroundColor(Color.parseColor("#3E0600")); 
     } else if (randomInt < 50 && randomInt <= 60) { 
      btn.setBackgroundColor(Color.parseColor("#000000")); 
     } else if (randomInt > 60 && randomInt <= 70) { 
      btn.setBackgroundColor(Color.parseColor("#003E0F")); 

     } else if (randomInt > 70 && randomInt <= 80) { 
      btn.setBackgroundColor(Color.parseColor("#007A1D")); 

     } else if (randomInt > 80 && randomInt <= 90) { 
      btn.setBackgroundColor(Color.parseColor("#00C42F")); 

     } else { 
      btn.setBackgroundColor(Color.parseColor("#11FF4A")); 

     } 
     Log.d("TAG", "randnumber" + randomInt); 

     btn.setLayoutParams(new LinearLayout.LayoutParams(randomInt, 40)); 

     btn.setId(i); 
     btn.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       // TODO Auto-generated method stub 
       Log.d("TAG", "get id" + arg0.getId()); 
      } 
     }); 
     TextView text1 = new TextView(this); 
     text1.setText("1"); 
     text1.setTextColor(Color.parseColor("#000000")); 
     text1.setLayoutParams(new LinearLayout.LayoutParams(60, 40)); 
     lay1.setOrientation(LinearLayout.HORIZONTAL); 
     lay1.setGravity(Gravity.CENTER_VERTICAL); 
     // lay1.setPadding(0, 10, 0, 10); 
     lay1.addView(text); 
     lay1.addView(line); 
     lay1.addView(btn); 
     lay1.addView(text1); 
     lay.setOrientation(LinearLayout.VERTICAL); 
     lay.addView(lay1); 
     linear.addView(lay); 
    } 
} 

} 

다음은 XML 코드입니다. 당신이 수단이 그것을 사용하려는 경우

<LinearLayout 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:orientation="vertical" 
tools:context=".MainActivity" > 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scrollbars="vertical" > 

    <LinearLayout 
     android:id="@+id/linear" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 
    </LinearLayout> 
</ScrollView> 

+0

그 그냥 생각. 그렇지 않으면 그대로 두십시오. –