2012-03-09 108 views
0

我有兩個問題。Android,如何將畫廊粘貼到屏幕的左側?

第一,當我加載活動的第一件畫廊是在中間。如何讓android將它對齊到左邊? (實際上我使用align =「left」,但它似乎不起作用)

第二,我的活動包括三個項目,標題,正文和頁腳。目前頁腳(畫廊)位於身體之上。我希望身體的底部停留在頁腳上方而不是頁腳後面。

任何建議表示讚賞。圖像是這樣的。

enter image description here

代碼:

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

<RelativeLayout 
    xmlns:android   = "http://schemas.android.com/apk/res/android" 
    android:layout_width = "fill_parent" 
    android:layout_height = "fill_parent" 
    android:background = "@drawable/bg" > 


    <!-- Loading header of this UI which is coded separately --> 
    <include 
     android:id="@+id/header" 
     layout="@layout/header_bar" /> 



    <GridView 
     android:id="@+id/news_gridview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dip" 
     android:numColumns="2" 
     android:verticalSpacing="5dp" 
     android:horizontalSpacing="5dp" 
     android:layout_below="@id/header" 
     android:layout_centerInParent="true" /> 


    <Gallery 
     android:id="@+id/gallery" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" /> 

</RelativeLayout> 

回答

3

爲1:

檢查這個現有的SO問題:

For 2nd: - 您需要在您的GridView中包含android:layout_above="@+id/gallery"。 - Remoev android:layout_centerInParent="true"

總之,定義:

<GridView 
     android:id="@+id/news_gridview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginTop="10dip" 
     android:numColumns="2" 
     android:verticalSpacing="5dp" 
     android:horizontalSpacing="5dp" 
     android:layout_below="@+id/header" 
     android:layout_above="@+id/gallery"/> 
+0

謝謝帕雷什。而不是使用如此多的代碼行我喜歡使用「gallery.setSelection(imAdapter.getCount()/ 2);」將畫廊帶到中間。但我提出了第二條建議的建議,但發生了錯誤,我不知道爲什麼,但我無法使用它。再次感謝。 – Hesam 2012-03-09 06:17:17

相關問題