0

線形レイアウトでビューを別のビューの下に配置することは可能ですか?

私はこのようなことをしたいと思います: http://i.imgur.com/LWgtBKO.png?1

これは線形レイアウトで可能ですか?

また、固定値(固定の高さ/幅など)を使用せずにこれを実行したいと思います。これらのビューは、画面を均等に埋める必要があります(例のように)。

前もって感謝します

4

5 に答える 5

1

layout_belowいいえ、線形レイアウトでは使用できません。

アイテムを別のアイテムの下に配置する場合は、使用しますandroid:orientation="vertical"

そして、それらを並べて配置したい場合は、使用しますandroid:orientation="horizontal"

于 2013-05-25T17:59:02.580 に答える
0

はい、可能ですが、なぜ線形レイアウトを使用する必要があるのでしょうか?

これは線形レイアウトのコードです:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="2" >

    <!-- MAIN CONTAINER -->

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

        <!-- FIRST CONTAINER -->

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

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

            <!-- CHILD OF FIRST CONTAINER -->

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TableLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
            </TableLayout>
        </LinearLayout>
    </LinearLayout>

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

        <!-- SECOND CONTAINER -->

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

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

            <!-- CHILD OF SECOND CONTAINER -->

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TableLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
            </TableLayout>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

これは RelativeLayout を使用したコードです:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dp">

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

    <TextView
        android:id="@+id/textView1"
        android:layout_toRightOf="@+id/imageView1"
        android:layout_alignTop="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TableLayout
        android:layout_toRightOf="@+id/imageView1"
        android:layout_below="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </TableLayout>

    <ImageView
        android:id="@+id/imageView2"
        android:layout_toRightOf="@+id/textView1"
        android:layout_alignTop="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/textView2"
        android:layout_toRightOf="@+id/imageView2"
        android:layout_alignTop="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TableLayout
        android:layout_toRightOf="@+id/imageView2"
        android:layout_below="@+id/textView2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </TableLayout>

</RelativeLayout>

私のコードがあなたの質問で与えられた写真のように 100% 表示されるかどうかは 100% 確信が持てませんが、私のコードからそのようなレイアウトを作成する方法の全体像を把握できると確信しています。Android を学習したばかりで、relativelayout について学習していないという理由だけで線形レイアウトを使用したい場合は、相対レイアウトのコードが線形レイアウトのコードよりもはるかに単純であることがわかるので、今がそれを学ぶのに最適な時期だと思います. 私の答えがお役に立てば幸いです。別の質問がある場合は、コメントでお気軽にお問い合わせください:)

于 2013-05-25T18:13:06.307 に答える