如何在TableRow中的ImageView下放置按钮

问题描述 投票:0回答:1

大家好,我确实有这个:

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

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="match_parent"
                android:layout_height="0dip"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/imageView2"
                    android:layout_width="119dp"
                    android:layout_height="83dp"
                    android:layout_weight="0"
                    app:srcCompat="@drawable/icon" />

                <Button
                    android:id="@+id/button1"
                    android:layout_width="0dp"
                    android:layout_height="50dp"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:layout_below="@id/imageView" // This is the solution I found which doesn't seems to work on tablerow
                    android:text="cccccccccccccccccccccccccccc" />

                <Button
                    android:id="@+id/button2"
                    android:layout_width="0dp"
                    android:layout_height="50dp"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:text="Button" />

            </TableRow>

            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="match_parent"
                android:layout_height="0dip"
                android:layout_weight="1" >

                <Button
                    android:id="@+id/button3"
                    android:layout_width="0dp"
                    android:layout_height="50dp"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:text="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" />

                <Button
                    android:id="@+id/button4"
                    android:layout_width="0dp"
                    android:layout_height="50dp"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:text="ddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" />
            </TableRow>

        </LinearLayout>

我想在ImageView下使用一个按钮,但功能“ android:layout_below =” @ id / imageView“在TableRow上不起作用。现在的样子:enter image description here

所以我希望该图像位于“ CCCCCCC”按钮上方,但我无法使其正常工作

android android-linearlayout tablerow
1个回答
0
投票

layout_below仅用于RelativeLayout。为了使其工作,将ImageViewTextView包裹到RelativeLayout中,替换为:

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="119dp"
                android:layout_height="83dp"
                android:layout_weight="0"
                app:srcCompat="@drawable/icon" />

            <Button
                android:id="@+id/button1"
                android:layout_width="0dp"
                android:layout_height="50dp"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:layout_below="@id/imageView" // This is the solution I found which doesn't seems to work on tablerow
                android:text="cccccccccccccccccccccccccccc" />

with

         <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                >

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="119dp"
                android:layout_height="83dp"
                android:layout_weight="0"
                app:srcCompat="@drawable/icon" />

            <Button
                android:id="@+id/button1"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_gravity="center"
                android:layout_below="@id/imageView" // This is the solution I found which doesn't seems to work on tablerow
                android:text="cccccccccccccccccccccccccccc" />

         </RelativeLayout>
© www.soinside.com 2019 - 2024. All rights reserved.