2011-11-04 43 views
0

我有一組需要在屏幕頂部設置的10個圖像視圖。在肖像模式下,它是完美的按照要求。但是當我將屏幕方向轉爲橫向時,圖像數量保持不變,但寬度明顯不符合佈局。我的意思是一組10個圖像視圖只填充了屏幕的50%。一組圖像視圖不適合橫向模式

我試過很多不同的方式,但還是我沒有能夠做到這一點景觀

,這裏是我的xml說main.xml中

<RelativeLayout android:id="@+id/relativeLayout1" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android"> 

<LinearLayout 
android:layout_alignParentTop="true" 
android:id="@+id/progresslayout" 
android:orientation="horizontal" 
android:layout_width="wrap_content" android:layout_height="wrap_content"> 

<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb1" 
    android:layout_height="wrap_content" android:layout_width="wrap_content" 
    android:layout_alignParentLeft="true"></ImageView> 


<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb2" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"></ImageView> 

<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb3" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"></ImageView> 

<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb4" 
    android:layout_toRightOf="@+id/pb3" android:layout_height="wrap_content" 
    android:layout_width="wrap_content"></ImageView> 

<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb5" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"></ImageView> 

<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb6" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"></ImageView> 

<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb7" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"></ImageView> 

<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb8" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"></ImageView> 

<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb9" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"></ImageView> 

<ImageView android:src="@drawable/progressgreen" android:id="@+id/pb10" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"></ImageView> 

    </LinearLayout> 

    </RelativeLayout> 

我試圖讓機器人:layout_weight =」「財產也仍然沒有用。我注意到這裏有趣的是,而不是圖像視圖,如果我嘗試提交一些按鈕或編輯文本同樣的事情,它工作正常進行縱向和橫向

+0

你的LinearLayout寬度和高度也應該是這樣的android:layout_width = 「FILL_PARENT」 機器人:layout_height = 「FILL_PARENT」 –

+0

@Padma庫馬爾,我已經試過了 – tejas

回答

1

你去那裏

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/relativeLayout1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<LinearLayout 
    android:id="@+id/progresslayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@+id/pb1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_launcher" > 
    </ImageView> 

    <ImageView 
     android:id="@+id/pb2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_launcher" > 
    </ImageView> 

    <ImageView 
     android:id="@+id/pb3" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_launcher" > 
    </ImageView> 

    <ImageView 
     android:id="@+id/pb4" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_launcher" > 
    </ImageView> 

    <ImageView 
     android:id="@+id/pb5" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_launcher" > 
    </ImageView> 

    <ImageView 
     android:id="@+id/pb6" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_launcher" > 
    </ImageView> 

    <ImageView 
     android:id="@+id/pb7" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_launcher" > 
    </ImageView> 

    <ImageView 
     android:id="@+id/pb8" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_launcher" > 
    </ImageView> 

    <ImageView 
     android:id="@+id/pb9" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_launcher" > 
    </ImageView> 

    <ImageView 
     android:id="@+id/pb10" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/ic_launcher" > 
    </ImageView> 
</LinearLayout> 

記住你的圖像資源,以取代android:src="@drawable/ic_launcher"。這將在屏幕上方創建十個圖像,並在彼此之間很好地進行間隔。

如果您不需要圖像之間的空間,請爲每個圖像使用android:scaleType="fitXY"屬性。祝你好運。

+0

我已經試過這一點。在這種情況下,圖像適合,但圖像不可見。如果我將體重設爲0或0.2而不是1,則圖像會出現但不適合佈局 – tejas

+0

您是否嘗試過使用其他圖像?在發佈之前我已經過測試。 – PH7

+0

是的,我嘗試過使用其他圖像。這隻發生在圖像視圖中,對於像編輯文本或按鈕這樣的字段這是可行的 – tejas

0

在的LinearLayout標籤去除

機器人:取向= 「水平」

屬性並改變

機器人:layout_width = 「WRAP_CONTENT」

試試吧

0

嘗試使用android:layout_weight="1"android:layout_width="fill_parent"。這將確保所有對象共享整個佈局寬度,並且每個對象都佔用相同的空間。

0

嘗試,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/relativeLayout1" 
android:weightSum="2" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<LinearLayout 
    android:id="@+id/progresslayout" 
    android:layout_weight="1" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:weightSum="10" 
    android:orientation="horizontal" > 
// Your ImageViews Here 
    <ImageView 
    android:id="@+id/pb10" 
    android:layout_weight="1" 
    android:layout_width="0dp" 
    android:layout_height="fill_parent" 
    android:src="@drawable/image1" > 
    </ImageView> 

</LinearLayout> 
</LinearLayout> 
+0

父級的內部線性佈局應該只是相對佈局 – tejas

+0

我可以知道爲什麼它的必要嗎?你在談論佈局包含10個圖像? – MKJParekh

+0

不,我正在談論包含內部佈局的最外面的線性佈局。這只是整個佈局的一部分。許多其他事情與外部相對佈局相關聯,所以需要 – tejas

相關問題