2012-03-21 109 views
1

我正在創建一個在Logitech revue上運行的應用程序。用戶界面顯示在電視屏幕上。如何爲電視設置任何佈局(寬度,高度)?

使用模擬器運行時佈局看起來很好。但是當它顯示在電視屏幕上時,部分內容會被切斷。

如何調整:

  • 的android:layout_width
  • 安卓layout_height

,使其適合屏幕無論大小? fill-parent和wrap_content似乎沒有解決這個問題。

如果可能的話,你能指導我一些資源嗎?或者提供一個例子嗎?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <GridView 
     android:id="@+id/propGridView" 
     android:layout_width="619dp" 
     android:layout_height="487dp" 
     android:layout_gravity="center_vertical" 
     android:numColumns="5" 
     android:paddingTop="20dp" > 
    </GridView> 

    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="380dp" 
     android:layout_height="508dp" 
     android:layout_gravity="center" 
     android:orientation="vertical" > 

     <FrameLayout 
      android:id="@+id/frameLayout1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" > 

      <ImageView 
       android:id="@+id/propertyThumbnail" 
       android:layout_width="match_parent" 
       android:layout_height="280dp" 
       android:layout_weight="0.10" 
       android:paddingTop="20dp" 
       android:src="@drawable/wow" /> 
     </FrameLayout> 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:paddingTop="5dp" 
      android:text="Title" 
      android:textSize="20dp" /> 

     <TextView 
      android:id="@+id/description" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="Description" 
      android:textSize="10dp" /> 
    </LinearLayout> 

</LinearLayout> 
+0

後的XML爲你的佈局,所以我們可以看看一切 – dymmeh 2012-03-21 20:26:34

+0

的FrameLayout裏@ dophie。我發佈了xml – Fabii 2012-03-21 20:36:32

+0

看看我的答案,看看它是否有幫助。 – dymmeh 2012-03-21 20:50:38

回答

2

設置固定值可能會導致您的視圖出現問題。防爆。如果你有一個200dip寬度的視圖,另一個寬度爲400dip,並且屏幕支持的寬度爲500dip,那麼你的視圖中會有一些事物被切斷。

看看你的寬度使用權重。如果您提供一個視圖的權重爲.6,另一視圖的權重爲.4,則第一個視圖將佔用屏幕的60%,其他40%。這會阻止您將其他視圖從屏幕上移開。

我修改了XML來說明其使用

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <GridView 
     android:id="@+id/propGridView" 
     android:layout_width="0dip" 
     android:layout_weight=".6" 
     android:layout_height="match_parent" 
     android:layout_gravity="center_vertical" 
     android:numColumns="5" 
     android:paddingTop="20dp" > 
    </GridView> 

    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="0dip" 
     android:layout_weight=".4" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     android:orientation="vertical" > 

     <ImageView 
      android:id="@+id/propertyThumbnail" 
      android:layout_width="match_parent" 
      android:layout_height="280dp" 
      android:layout_weight="0.10" 
      android:paddingTop="20dp" 
      android:src="@drawable/icon" /> 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:paddingTop="5dp" 
      android:text="Title" 
      android:textSize="20dp" /> 

     <TextView 
      android:id="@+id/description" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="Description" 
      android:textSize="10dp" /> 
    </LinearLayout> 

</LinearLayout> 

我刪除了,你有,因爲它基本上是無用

+0

真棒,謝謝你,它像一個魅力工作。 – Fabii 2012-03-21 20:50:44

+0

我剛剛編輯了我的答案,並從XML中刪除了FrameLayout。它沒有做任何事情,也沒有嵌套視圖(如果可以避免的話)。但結果看起來是一樣的。 – dymmeh 2012-03-21 20:52:06

0

這應該做的伎倆:

android:layout_width="MATCH_PARENT" 
android:layout_height="MATCH_PARENT" 

重新檢查你的完整佈局有佈局PARAMS設置爲「WRAP_CONTENT」視圖的父母。這些會搞砸你的佈局。

+0

這適用於所有視圖還是僅適用於最頂層視圖?請看看我上面發佈的xml。 – Fabii 2012-03-21 20:38:29

相關問題