堆叠两个图像按钮
我有两个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 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.