我想在文本的右侧制作两个大小相同的单选按钮,其中包含自定义背景,文本和图像。由于这些与标准的“按钮”有多么不同,我使用可点击的“RelativeLayout”来制作它们。为什么我的“居中”对象在我的RelativeLayout中稍微偏离中心?
文字和图像的高度不同,但我希望每个文字和图像在按钮中垂直居中。我还希望文本+图像的组合在按钮中水平居中。第二部分是我遇到的麻烦;它偏离中心,靠近左侧。在下图中,左侧是我想要的,但右侧是发生了什么。其中一个按钮(具有较长文本的按钮)上的图像也被调整为较小,尽管按钮右侧仍有足够的空间。
这里是我的代码:
<LinearLayout
android:baselineAligned="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/my_button"
android:background="@drawable/radio_button"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="@+id/button_textview"
android:text="@string/button_label"
android:textAppearance="?android:attr/textAppearanceButton"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<ImageView
android:contentDescription="@string/image_description"
android:id="@+id/button_imageview"
android:layout_centerVertical="true"
android:src="@drawable/my_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/button_textview">
</ImageView>
</RelativeLayout>
<RelativeLayout
... same thing for the second button ...
</RelativeLayout>
</LinearLayout>
我在做什么错?
这并没有改变任何东西,但谢谢。我在那里有一个希望。我之所以不使用drawableRight,是因为它将它绘制在按钮的右边缘,而不是立即在文本的右边。 – Kalina
你可以在你的问题中更新你现在使用的布局吗? –
@TheBeatlemaniac编辑回答。 –