2015-08-15 33 views
0

我正在努力嘗試在Android中同時創建水平和垂直堆疊的圖像。我嘗試了一堆不同的方法,但似乎無法達到目標。我會上傳一個我要去的圖片,但是沒有stackoverflow點,所以這裏是我的代碼。希望你們能幫我阻止我的頭靠在牆上。除非我仍然關於這個完全錯誤,似乎我的問題是在最後一個相對佈局 - 我不允許有一個相對佈局是在LinearLayout中的特定對象的權利?此外,我如何做到這一點,而不在我的圖像重疊?:如何在Android中創建水平和垂直堆疊的圖像?

編輯,顯示代碼tableLayout:

<TableLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:xlmns="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:orientation="vertical" 
tools:context=".MainActivity$PlaceholderFragment"> 

<TextView android:id="@+id/section_label" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<TableRow 
    android:id="@+id/tableRow1Buttons" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    > 

<Button 
    android:layout_column="0" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="FILTER" 
    android:id="@+id/filterButton" 
    /> 

<Button 
    android:layout_column="1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Neighborhood?" 
    android:id="@+id/neighborhoodButton" 
    /> 

</TableRow> 



<TableRow 
android:id="@+id/tableLayoutListing1" 
android:layout_width="match_parent" 
android:layout_height="wrap_content"> 


    <ImageView 
    android:layout_column="0" 
    android:layout_width="0dp" 
    android:layout_weight=".70" 
    android:layout_height="300dp" 
    android:id="@+id/listingImage1" 
    android:src="@drawable/alex_room" 
    android:layout_gravity="top" /> 

<ImageView 
    android:layout_column="1" 
    android:layout_width="0dp" 
    android:layout_weight=".30" 
    android:layout_height="100dp" 
    android:id="@+id/listingImage2" 
    android:src="@drawable/alex_room_two" 
    android:layout_gravity="top" /> 


    <ImageView 
     android:layout_toRightOf="@+id/listingImage1" 
     android:layout_below="@+id/listingImage2" 
     android:layout_width="0dp" 
     android:layout_weight=".30" 
     android:layout_height="100dp" 
     android:id="@+id/listingImage3" 
     android:src="@drawable/livingroom" 
     android:layout_gravity="bottom" /> 

</TableRow> 

</TableLayout> 
+0

爲什麼不把它放在一個相對的佈局?線性佈局使得代碼更快速,但對於複雜的佈局,相對佈局更加靈活。 – maxib7

回答

0

如果你想堆放在水平和垂直兩個對象,我不會建議使用一個LinaerLayout位置。使用兩個不同方向的兩個LinearLayouts也是一個壞主意。

更簡單的方法是使用TableLayout,它可以水平和垂直堆疊對象。

+0

感謝Henry解決了很多問題。任何有關如何最好地使某些細胞比其他細胞更大的建議?我一直在嘗試使用layout_width =「0dp」和layout_weight =「.70」,併爲行layout_weight =「。30」中的其他圖像,但似乎使第二個圖像上排在行的右上角?另外,如何最好地處理1行圖像實際上是2行大小的行,並且我想要將2個圖像堆疊在右側?現在第三張圖片出現在它們的下面? – Noobprogrammer

+0

嘿,這個傢伙現在已經解決了。 – Noobprogrammer