2015-08-15 110 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

相关问题