堆叠两个图像按钮

发布于 2024-09-10 20:43:45 字数 1304 浏览 1 评论 0原文

我有两个 ImageButtons,我试图将一个堆叠在另一个之上。我本质上是想制作一个带有两个大按钮的屏幕,每个按钮占据 50% 的可用空间。代码如下。这是它生成的布局的捕获 https://i.sstatic.net/RoYIp.png 我已经在父级上使用了layout_gravity 和重力。将两个子级设置为layout_height=fill_parent 不起作用,将父级的重力设置为fill_vertical 也不起作用。

        <!-- Notes tab -->
        <LinearLayout android:id="@+id/tabNotes"  
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"             
            android:padding="6dp"
            android:orientation="vertical">                                                 
            <ImageButton android:src="@drawable/ic_btn_speak_now" android:id="@+id/imgSpeakNow"                         
                android:background="#FFFF00"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                />                  
            <ImageButton android:src="@drawable/ic_btn_compose" android:id="@+id/imgCompose" 
                android:background="#FF00FF"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"                                    
                />
        </LinearLayout>

I have two ImageButtons, and I am trying to stack one on top of the other. I essentially want to make a screen with two big buttons that each take up 50% of the available space. The code is below. Here is a capture of the layout it yields https://i.sstatic.net/RoYIp.png I have played around with layout_gravity and gravity on the parent. Setting both chidren with layout_height=fill_parent doesn't work nor does setting the parent's gravity to fill_vertical.

        <!-- Notes tab -->
        <LinearLayout android:id="@+id/tabNotes"  
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"             
            android:padding="6dp"
            android:orientation="vertical">                                                 
            <ImageButton android:src="@drawable/ic_btn_speak_now" android:id="@+id/imgSpeakNow"                         
                android:background="#FFFF00"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                />                  
            <ImageButton android:src="@drawable/ic_btn_compose" android:id="@+id/imgCompose" 
                android:background="#FF00FF"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"                                    
                />
        </LinearLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑白记忆 2024-09-17 20:43:45

使用 android:layout_weight;将两个按钮设置为具有相同的值。

使用RelativeLayout 而不是LinearLayout 也可能有所帮助。

Use android:layout_weight; set both buttons to have the same value.

Using RelativeLayout instead of LinearLayout may help, too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文