2011-12-16 90 views
0

我無法弄清爲什麼我的圖像不在我的圖像視圖範圍內。相反,它漂浮在左邊並隱藏起來。這是因爲圖形界面沒有顯示它嗎?圖像越界圖像視圖

編輯:

我編輯的原代碼,以更清楚地顯示我遇到的問題,並增加了一個圖(我希望圖像中紅色框顯示):

enter image description here

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
    android:id="@+id/top_container" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1"  
    android:gravity="center" 
    > 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     > 
     <View 
      android:layout_height="fill_parent" 
      android:layout_width="0dp" 
      android:layout_weight="195" 
      android:background="#00FF00"/> 
     <ImageView 
      android:id="@+id/img" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:background="#ff0000" 
      android:src="@drawable/img" /> 

     <View 
      android:layout_height="fill_parent" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:background="#0000FF" 
     /> 
    </LinearLayout> 
</LinearLayout> 

回答

0

好吧我有它的工作。 「block_container」的高度屬性設置爲隨機200dp,您可以根據自己的需要更改高度,或者將其設置爲「wrap_content」。我在仿真器和設備上測試了這一點。

我還假設你想讓所有三個塊的間距相等。請注意父級「block_container」的weight_sum是否爲9?那麼這些孩子的寬度是相等的,因爲他們的體重是3(每塊3塊* 3重量=總共9塊)。

我注意到它看起來像你試圖直接使用重量作爲寬度例如重量爲569.請直接記住重量!=寬度。

編輯:添加缺少的ID從一些我更新的問題有點意見

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

    <LinearLayout 
     android:id="@+id/block_container" 
     android:layout_width="fill_parent" 
     android:layout_height="200dp" 
     android:orientation="horizontal" 
     android:weightSum="9" 
     > 
     <View 
      android:id="@+id/left_block" 
      android:layout_height="fill_parent" 
      android:layout_width="0dp" 
      android:layout_weight="3" 
      android:background="#00FF00"/> 
     <ImageView 
      android:id="@+id/img" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="3" 
      android:background="#ff0000" 
      android:src="@drawable/logo" /> 

     <View 
      android:id="@+id/right_block" 
      android:layout_height="fill_parent" 
      android:layout_width="0dp" 
      android:layout_weight="3" 
      android:background="#0000FF" 
     /> 
    </LinearLayout> 
</LinearLayout> 
0

爲什麼你將android:layout_height設置爲0dp?除非我將其更改爲類似fill_parent的東西,否則我甚至無法展示它。

無論哪種方式,其因爲您的layout_weight父母LinearLayout。爲您的ImageView指定一個較大的layout_weight,它將會出現。

<ImageView 
     android:id="@+id/my_img" 
     android:gravity="center" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="279" 
     android:src="@drawable/my_img" /> 

這對我有效..但數學可能是不正確的。

+0

屬性。也許我不理解什麼?我需要增加體重嗎?圖像是否應該處於邊界? – prostock 2011-12-17 00:09:01

+0

你甚至嘗試過嗎?我複製了問題並通過增加ImageView的重量來解決問題。 – styler1972 2011-12-17 02:55:29

0

我不知道從哪裏開始的各種問題與你發佈什麼,甚至進一步調試之前的一些簡單的觀察:

  • 你的佈局,都需要IDS(如機器人:ID =「@ + ID/another_layout「)
  • 您對0dp的第二線性佈局的寬度
  • 你的第一線佈局有0 DP的高度,與前組合我很驚訝它呈現在所有
  • 最後的內部線性佈局的寬度爲0dp

你想達到什麼目的?對我來說,似乎有很多佈局,除非你刪除了一些元素,以便更容易理解?您可以發佈您正在嘗試做的事情的簡單圖片,或許我們可以幫助您完善標記?