2010-12-05 43 views
4

我为Android 2.2构建了这个版本设置android:背景正在搞乱我的单选按钮的文本

这是我的代码。 java是由eclipse生成的。我改变了xml。

package foo.bar.radiobuttontest; 

import android.app.Activity; 
import android.os.Bundle; 
import foo.bar.radiobuttontest.R; 

public class rbt extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
    } 
} 

这里是我的RES /布局/ main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <RadioGroup 
     android:id="@+id/orientation" 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="5px"> 
     <RadioButton 
      android:id="@+id/horizontal" 
      android:background="#aa0000" 
      android:text="horizontal" 
     /> 
     <RadioButton 
      android:id="@+id/vertical" 
      android:text="vertical" 
     /> 
    </RadioGroup> 
</LinearLayout> 

虽然与单选按钮我开始做一个非常简单的应用试验。它看起来像这样:

*水平×垂直

没有很好的理由,我想我会改变背景颜色。我通过改变RadioGroup元素的背景开始,一切都按照预期工作。然后,只是为了好玩,但我会改变组中单选按钮之一的背景。这可以在上面的main.xml中看到。这样做后,我注意到了单选按钮的文字现在覆盖的单选按钮,页面现在看起来是这样的:

* rizontal *垂直

除了可以仍然有种看到水平的“豪”,他们只是由单选按钮覆盖

这是预期的行为?

+0

我会......绝对不会说这种预期的行为。自己尝试一下,我唯一能想到的就是他们使用了一个有限内容区域的空NinePatch ......但这似乎极其不可能。 – kcoppock 2010-12-05 07:05:23

+0

刚刚发现了同样的事情!叹。你有没有找到任何其他答案或解决方法? – 2012-11-06 18:15:34

回答

5

我一直在寻找一点,我发现@kcoppock提出的是正确的。 Here你找到单选按钮样式,this是引用的背景图片:

alt text

这是一个九宫格,其内容区不包括“无线”领域。我想可以从这张图片开始制作自定义背景。