0

I can't figure out how my layout should look like. I have a fragment. Inside it, I have scrollView (as I wish to support both orrientations), inside ScrollView I would like to have four images evenly distributed ( like this http://numberexplosion.com/wp/wp-content/uploads/2012/04/square-4.gif ). But I just can't figure out a way to do it, I have tried relative, linear, tablelayouts, but can't get such view :/.

My current layout:

<?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:gravity="center_vertical|center_horizontal" >

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <ImageView
                    android:id="@+id/imageView1"
                    android:layout_width="150dp"
                    android:layout_height="150dp" />

                <ImageView
                    android:id="@+id/ImageVieww2"
                    android:layout_width="150dp"
                    android:layout_height="150dp" />

            </TableRow>

            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <ImageView
                    android:id="@+id/ImageVieww3"
                    android:layout_width="150dp"
                    android:layout_height="150dp" />

                <ImageView
                    android:id="@+id/ImageVieww4"
                    android:layout_width="150dp"
                    android:layout_height="150dp" />

            </TableRow>

            <TableRow
                android:id="@+id/tableRow3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >
            </TableRow>

        </TableLayout>

    </ScrollView>

This layout looks nearly as I wish it to be, but the image size is only 150dp, and not filling the whole screen in some cases. My imageView sources are different, but I would like to imageViews to fill my fragment. Any ideas what I'm doing wrong?

4

2 回答 2

0

你可以做这样的事情。我知道它的布局很重,但它会解决你的问题。我只使用了两个horizontal Linear layouts,我在每个中Vertical Linear Layout. 放置了 2 个按钮。horizontal linear layoutweight 1

垂直布局 横向布局

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/ImageView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:scaleType="fitXY"
            android:src="@drawable/no_image" />

        <ImageView
            android:id="@+id/ImageView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:scaleType="fitXY"
            android:src="@drawable/no_image" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/ImageView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:scaleType="fitXY"
            android:src="@drawable/no_image" />

        <ImageView
            android:id="@+id/ImageView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:scaleType="fitXY"
            android:src="@drawable/no_image" />

    </LinearLayout>

</LinearLayout>
于 2013-04-17T12:17:03.480 回答
0

一个相当好的解决方案是使用LinearLayout包含 2LinearLayouts每个包含 2 Views。诀窍是在儿童(2和 4 )上使用layout_width/ layout_heightof0dp和。layout_weightLinearLayoutsViews

您可能还想尝试GridLayout(not GridView),它可从 Android 4.0 ( http://developer.android.com/reference/android/widget/GridLayout.html ) 和 support-library-v7 中的 2.1 获得。

于 2013-04-17T12:05:33.210 回答