2

我需要在我的项目中创建新活动,并且我想展示图片。我想要创建的布局是这样的。

在此处输入图像描述

所有高度都必须具有“wrap_content”属性。

我必须使用哪些布局?

4

4 回答 4

3

试试这个:

 <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <GridView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="66" >
        </GridView>

        <GridView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="33" >
        </GridView>
    </LinearLayout>

    <GridView
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </GridView>
</LinearLayout>

注意:您可以使用任何其他视图而不是 GridView,只要确保属性相同即可。

这就是你要找的

于 2013-06-14T08:47:02.763 回答
0

我想你想创建一个 StaggeredGridView。

StaggeredGridView 是 Android 的实验性 StaggeredGridView 的修改版本。StaggeredGridView 允许用户创建具有不均匀行的 GridView,类似于 Pinterest 的外观。包括自己的 OnItemClickListener 和 OnItemLongClickListener、选择器和固定位置恢复。

使用这个库。

希望这可以帮助 :)

于 2013-06-14T08:25:29.163 回答
0

考虑使用TableLayoutGridView并在子级上使用属性layout_weight

您的第一个孩子 (66%) 的布局权重为 2,第二个 (33%) 的布局权重为 1。

那么第一个孩子将占据宽度的 2/3(66%),第二个孩子占据 1/3,即 33%。

并使用layout_span属性展开两列的最后一个视图。

例如 :

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="*" >

    <TableRow>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"/>
    <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>
    </TableRow>

    <TableRow>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_span="2" />
    </TableRow>
</TableLayout>

另请参阅该问题以获取有关 layout_weight 的解释。

于 2013-06-14T08:31:01.077 回答
0

为什么要坚持使用 wrap_content?您有“固定”宽度的框(66% 和 33%)。我敢肯定,您可以使用 sp/dp 单位来实现这一点。当然,经过一些调整。

有关此主题的更多信息,请访问 http://developer.android.com/guide/practices/screens_support.htmlAndroid 上的“px”、“dp”、“dip”和“sp”有什么区别?

于 2013-06-14T08:36:36.600 回答