2

내 XML이 2 LinearLayouts입니다.LinearLayout에 다른 뷰를 팽창시키는 방법?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
    <LinearLayout 
      android:id="@+id/ll_one" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      /> 
    <LinearLayout 
      android:id="@+id/ll_two" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      /> 
</LinearLayout> 

http://android.arnodenhond.com/components/graphview에서 GraphView를 다운로드했습니다. 이 클래스는 View를 확장합니다. 나는 기본적으로

String[] verlabels = new String[]{"aim", "25%", "50%", "75%", "start"}; 
String[] horlabels = new String[]{"this", "max"}; 

float[] values = new float[]{2.0f, 6.0f}; 
aaaGraphView graphView = new aaaGraphView(this, values, "Graph One", 
     horlabels, verlabels, aaaGraphView.BAR); 

float[] values2 = new float[]{1.0f, 12.0f}; 
aaaGraphView graphView2 = new aaaGraphView(this, values2, "Graph Two", 
     horlabels, verlabels, aaaGraphView.BAR); 

를 통해 2 그래프를 초기화 한 후 ll_twoll_onegraphViewgraphView2을 팽창하고 싶습니다.

어떻게해야합니까? 나는 LinearLayout

llOne = (LinearLayout) findViewById(R.id.ll_one); 

초기화했지만 그것은 inflate() 방법이 없습니다.

답변

5

당신이하지를 inflateLinearLayout 안에 또 다른 view이 있어야합니다. 그러면 LinearLayout 안에 다른 아이를 추가하기 만하면됩니다. 최선을 다하는 LinearLayout에서 addView() 방법을 사용하면됩니다. 다음은 예입니다.

llOne.addView(graphView); 
3

보기를 확장하는 클래스의 이름이 시도 aaaGraphView 경우 :

<package1.package2....aaaGraphView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

</package1.package2....aaaGraphView> 
+0

답변으로 표시하십시오. – breceivemail

+0

감사하지만 프로그래밍 방식으로이 작업을 수행 할 방법을 찾고있었습니다. – sandalone

3

내가 다른 선형 레이아웃에있는 LinearLayout이 방법을 추가 한이 방법을 시도

setContentView(R.layout.main); 
final ViewGroup vg = (ViewGroup) findViewById(R.id.ll_one); 
vg.addView(graphView); 
+0

감사하지만 addView() 메소드를 사용하면 훨씬 간단합니다. – sandalone

+0

더 간단한 방법은 내가 얻지 못하는 것을 의미합니까? 너는 그것을 복잡하게 만들고 싶어? – MKJParekh

+0

나는 ll_one을 LinearLayout으로 이미 초기화했고, 또 다른 단계'최종 ViewGroup vg = (ViewGroup) findViewById (R.id.ll_one);'을 도입했습니다. 당신의 대답은 좋았고 그 이유는 내가 그것을 투표했습니다. – sandalone