2014-09-30 32 views
0

在我的Android代碼中,我創建了一個圖形。但是在兩種不同的設備中,「match_parent」並不像應該那樣。不同的屏幕尺寸變化查看Android

這是company_header.xml

<RelativeLayout 
    android:id="@+id/rlForScreenShot" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" > 

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

     *<com.kite.chart.chart.ChartView 
      android:id="@+id/cvChart" 
      android:layout_width="match_parent" 
      android:layout_height="200dp" />* 

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

      <TextView 
       android:id="@+id/tvCompanyName" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Loading" /> 

      <TextView 
       android:id="@+id/tvCompanyPrice" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="20dp" 
       android:text="Loading" /> 

      <TextView 
       android:id="@+id/tvCompanyChange" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="20dp" 
       android:text="Loading" /> 
     </LinearLayout> 
    </LinearLayout> 
</RelativeLayout> 

當在谷歌Nexus 10上運行有和圖形中沒有空間在它下面的細節部分。

當它在Samsung Galaxy note3上運行時。圖表中有一個空格,下面是詳細信息。

當我更改android:layout_height = match_parent時,對於這兩個屏幕設備圖都消失。我認爲這應該可以解決這個問題,因爲在我的Android Manifest.xml中,我已經使用了所有屏幕大小。

  *<com.kite.chart.chart.ChartView 
      android:id="@+id/cvChart" 
      android:layout_width="match_parent" 
      **android:layout_height="match_parent**" />* 

感謝您的幫助。或者有無論如何,我可以解決這個使用CSS? Kingsley PS:我需要10個聲望才能發佈圖片,因此爲什麼不附上圖片。

回答

0

您可以嘗試一件事, 以編程方式獲取屏幕尺寸,並選擇適合所有屏幕尺寸的屏幕尺寸的百分比,並將其設置爲您查看。

嘗試這個例子

DisplayMetrics displaymetrics = new DisplayMetrics(); 
     getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); 
     int height = displaymetrics.heightPixels; 
     int width = displaymetrics.widthPixels; 
     int heightPercent=0; 
     LayoutParams lay; 
     if (height > width){ 
      heightPercent=(35*height)/100; 
      lay=new LayoutParams(LayoutParams.MATCH_PARENT, heightPercent); 
     }else { 
      heightPercent=(25*width)/100; 
      lay=new LayoutParams(LayoutParams.MATCH_PARENT, heightPercent); 
     } 

     view.setLayoutParams(lay); 
+0

我不知道你這個答案。你能否詳細解釋一下,或者一個例子會有幫助。 – 2014-09-30 14:08:23

+0

我編輯一個示例代碼,將幫助你,如果你沒有得到我的答案,請填寫免費查詢。 – Lokesh 2014-10-01 05:52:05

+0

現在看來這是唯一的選擇,因爲當我繪製後調試並檢查chartview的高度時,它仍然顯示爲空。所以它似乎必須給定一個確定的高度才能正確顯示。 – 2014-10-02 03:01:42