【发布时间】:2013-01-01 22:54:06
【问题描述】:
我有一个RelativeLayout,一个ImageButton,一个ToggleButton 和其他一些控件。两个按钮都在 RelativeLayout 的右侧对齐。我希望它们具有相同的高度。这是我的布局 xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:paddingBottom="10dip" >
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/copy"
android:layout_alignParentRight="true" />
<ToggleButton
android:id="@+id/buttonView"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:textOn="Hide"
android:textOff="View"
android:layout_toLeftOf="@id/imageButton"
android:layout_alignTop="@id/imageButton"
android:layout_alignBottom="@id/imageButton" />
<!-- ... other controls ... -->
</RelativeLayout>
我尝试设置layout_height="0dip" 并使用layout_alignTop 和layout_alignBottom 使ToggleButton 与ImageButton 具有相同的高度,但这不起作用:
如您所见,ToggleButton 对齐不正确,它总是略高于 ImageButton。我做错了什么?
在 Android 2.3 上测试
【问题讨论】:
-
所以不要使用“wrap_content”..当你使用它时,按钮将在他包含的内容的尺寸中..所以我建议你设置按钮的高度和自己的宽度..
-
您在图形布局编辑器中有这个问题吗?是只在 android 2.3 上还是在其他版本上?
-
@fiddler 我的图形布局没有问题(我使用最新的目标 SDK),在 Android 4.x 中没有问题,我仍然没有在 Android 3.x 上测试,问题似乎只出现在 2.x
-
@Janmejoy 没有机会使用自动高度? :(
-
@Andrew 为什么不可能
标签: android layout button alignment togglebutton