2014-01-11 4 views
0

내 XML에 문제가 있습니다. 차트 (aChartEngine 라이브러리)가 들어있는 LinearLayout을 가지고 있고 높이를 480dp로 설정하면 차트를 표시합니다. 높이를 wrap_content로 설정하면 아무 것도 표시되지 않습니다. 나는 부모님이나 어떤 것에 문제가 있다고 생각합니다. 다음은 전체 XML 파일입니다. tab4에서Android LinearLayout이 표시되지 않습니다.

<RelativeLayout 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" 

tools:context=".Sniffer" > 

<TabHost 
    android:id="@+id/tabHost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:background="@color/black" > 

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

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@color/white" > 
      </TabWidget> 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" > 

       <LinearLayout 
        android:id="@+id/tab1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:paddingLeft="10dp" 
        android:paddingRight="10dp" 
        android:orientation="vertical" > 

        <!-- removed some content here, 2 much space and not relevant --> 

       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/tab2" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:paddingLeft="10dp" 
        android:paddingRight="10dp" 
        android:orientation="vertical" > 

        <View 
         android:layout_width="1dp" 
         android:layout_height="30dp"> 
        </View> 

        <View 
         style="@style/Divider" 
         android:background="@color/semi_transparent"/> 

       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/tab3" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:paddingLeft="10dp" 
        android:paddingRight="10dp" 
        android:orientation="vertical" > 

        <View 
         android:layout_width="1dp" 
         android:layout_height="30dp"> 
        </View> 

        <View 
         style="@style/Divider" 
         android:background="@color/semi_transparent"/> 

       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/tab4" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:paddingLeft="10dp" 
        android:paddingRight="10dp" 
        android:orientation="vertical" > 

        <View 
         android:layout_width="1dp" 
         android:layout_height="30dp"> 
        </View> 

        <LinearLayout 
         android:id="@+id/chart" 
         android:layout_width="match_parent" 
         android:layout_height="500dp"      
         android:orientation="horizontal"> 
        </LinearLayout> 

       </LinearLayout> 
      </FrameLayout> 
     </LinearLayout> 
    </ScrollView> 
</TabHost> 
차트 ID로있는 LinearLayout있다. 그것이 내 차트를 배치하는 곳입니다. 나는 weight 속성과 0dip을 사용했지만 여전히 고정 된 높이에서만 작동했다.

LE : 선형 적으로 내용을 추가하기 때문에 LinearLayout이 비어 있습니다.

차트 코드 스 니펫.

public void createGraphCPU(List<BasicNameValuePair> values){ 

    mSeries = new CategorySeries(""); 
    mRenderer = new DefaultRenderer(); 
    statisticsTab.removeAllViews(); 

    Collections.shuffle(COLORS_LIST); 
    for(int i=0;i<values.size();i++){ 
     double value=Double.parseDouble(values.get(i).getValue()); 
     mSeries.add(values.get(i).getName(),value); 
     SimpleSeriesRenderer renderer = new SimpleSeriesRenderer(); 
     renderer.setColor(COLORS_LIST.get(i%COLORS_LIST.size())); 
     renderer.setDisplayChartValues(true); 
     mRenderer.addSeriesRenderer(renderer); 
    } 

    mRenderer.setChartTitleTextSize(20); 
    mRenderer.setChartTitle("CPU Energy Consumption"); 
    mRenderer.setLabelsTextSize(15); 
    mRenderer.setLegendTextSize(15); 
    mRenderer.setMargins(new int[] { 20, 15, 15, 0 }); 
    mRenderer.setZoomButtonsVisible(true); 

    if (mChartView != null) { 
      mChartView.repaint(); 
    } 
    else{ 
     mChartView = ChartFactory.getPieChartView(this, mSeries,mRenderer); 
     statisticsTab.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
    } 

} 
+0

id가 차트 인 LinearLayout은 항목이 없기 때문에 비어있는 것처럼 보입니까? – ayorhan

+0

지정하지 않는 것에 대해 죄송합니다. 프로그래밍 방식으로 항목을 추가합니다. aChartEngine 라이브러리의 GraphicView 만 있지만 거기에 있습니다 –

+0

그러면 차트보기에 할당 한 레이아웃 매개 변수가 문제 일 수 있습니다. 차트보기를 추가 할 때 코드를 공유 할 수 있습니까? – ayorhan

답변

0

당신은 당신이 android:layout_height과 당신이 wrap_content를 사용할 때 차트를 볼 수있는 고정 높이를 지정할 때 차트를 볼 수 있다고 말한다. 그렇다면이 동작의 이유는 차트 자체가 높이를 제공하지 않는다는 것입니다. 실제로 너비와 높이로 fill_parent을 지정합니다. 따라서 LinearLayout이 차트 (wrap_content)만큼 작기를 원하고 차트가 주변 LinarLayout (fill_parent)만큼 커지고 싶다면 Android에서 차트를 전혀 표시하지 않습니다.

해결 방법은 차트에 어떤 너비와 높이를주고 싶은지 물을 수 있습니다.

+0

현재 각각 다른 linearLayout에 세 개의 차트가 있습니다. Atm 각 linearlayout에는 높이가 있고 그 바로 뒤에있는 차트는 이전 linearLayout에 의해 잘립니다. 차트 자체의 고정 높이를 설정하고 클리핑이 사라 졌는지 확인하겠습니다. –

+0

차트 자체의 높이를 지정하는 방법을 찾을 수 없으며이를 포함하고있는 LinearLayout의 높이를 사용해야하는데 다른 선택의 여지가 없다고 생각합니다. 누군가가 aChartEngine을 사용하고 어떻게하는지 알고 있다면, 약간의 통찰력을 제공하십시오. 그렇게 말하면, 400dp의 높이를 가진 3 개의 선형 레이아웃을 만들어서 클립 아래가 아닌 다른 하나를 말하게 할 수 있습니다. 예. 두 번째 차트는 절반으로 잘립니다. RelativeLayout에 배치하고 layout_below를 사용했지만 여전히 차트가 잘립니다. –

+0

스크롤 할 수있는보기 내에서보기를 보려면 "ListView"를 사용해야합니다. ''LinearLayout''은 당신의 문제에 대한 올바른 해결책이 아닙니다. ListView를 사용하면 모든 목록 항목에 대해''400dp ''의보기 높이를 적용합니다. –

관련 문제