gpt4 book ai didi

android - RadioGroup 按钮图像被截断

转载 作者:太空狗 更新时间:2023-10-29 13:29:42 25 4
gpt4 key购买 nike

我在底部有一个带有四个按钮的 RadioGroup,用作我的应用程序的导航(我知道这对于 Android 应用程序来说是非标准的,但这是客户想要的)。它应该是这样的:

Radio Buttons - Correct

这在我的 Nexus 7 上看起来不错,在我的 IDE 中的模拟器和预览版中看起来也不错。然而,当我将它加载到 Galaxy S Note 2 上时,它是这样的:

Radio Buttons - Incorrect

图像被截断了,因为它们似乎被“移动”到这个特定设备的右边。我有一种感觉,在较小的设备上,它会更加倾斜和截断。当我手动执行大约 35dp 的负左边距时,它实际上看起来很完美并且它们对齐得很好(但当然该解决方案不适用于其他设备)。

奇怪的是,我的代码似乎并没有做任何特别的事情,而且看起来非常简单。仅供引用,即使我将其更改为只有三个按钮,它仍然将按钮向右移动,而不是真正将它们居中(尽管只有 3 个按钮时它们不会被截断)。我就是不明白为什么会这样,不管我尝试了多少调整重力、重量,甚至交换图像的东西。我目前只为这些使用/xhdpi 图像,每个图像的大小约为 130x130。

作为引用,这里是我的布局文件中 RadioGroup 的底层代码(它在 RelativeLayout 中):

    <RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tab_radio_group"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:background="@drawable/navigation_base"
android:paddingTop="15dp">
<RadioButton
android:id="@+id/button_scan"
style="@style/navbar_button"
android:drawableTop="@drawable/scan"/>
<RadioButton
android:id="@+id/button_view_order"
style="@style/navbar_button"
android:drawableTop="@drawable/view_order"/>
<RadioButton
android:id="@+id/button_complete_order"
style="@style/navbar_button"
android:drawableTop="@drawable/complete_order"/>
<RadioButton
android:id="@+id/button_settings"
style="@style/navbar_button"
android:drawableTop="@drawable/settings"/>
</RadioGroup>

这是 navbar_button 的样式元素:

    <style name="navbar_button">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:button">@null</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:layout_weight">1</item>
<item name="android:textSize">12dp</item>
</style>

我可能在这里遗漏了一些明显的东西,但是对此有什么想法吗?提前致谢!

最佳答案

为了解决这个问题,我最终不得不放弃 RadioGroup 和 RadioButtons,转而使用带有按钮的简单线性布局。它仍然是相对简单的代码,它只涉及稍微更改 Java 代码以使用普通按钮而不是 RadioButton。如果有兴趣,这是更改后的布局:

<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tab_radio_group"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:background="@drawable/navigation_base"
android:paddingTop="15dp">

<Button
android:id="@+id/button_scan"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@drawable/scan"/>
<Button
android:id="@+id/button_view_order"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@drawable/view_order"/>
<Button
android:id="@+id/button_complete_order"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@drawable/complete_order"/>
<Button
android:id="@+id/button_settings"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/transparent"
android:drawableTop="@drawable/settings"/>
</LinearLayout>

关于android - RadioGroup 按钮图像被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17128455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com