Android1.6模拟器上RadioGroup的RadioButton和文字的距离很近
来源:互联网 发布:手机单机游戏推荐知乎 编辑:程序博客网 时间:2024/05/01 06:46
今天修改一个BUG,出现了一个很纠结的问题。在使用Android的RadioGroup的RadioButton时,出现如下界面:
单选按钮和文字重叠在一起了,但在2.2上显示正常。。(全部是在大屏幕上进行的操作)
这个确实是我自己2了。
在XML中只需要设置一下:
android:paddingLeft="37dip"
这样就行了,如果是Java代码的话则设置:
radioBtnFemale.setPadding(55, 0, 0, 0);
开始由于xml和java文件中的单位不一样,所以文字也不一样,我开始设置的是一样子的,所以以为没解决,后来找了好久才找出来。太2了,汗。。。
效果如下:
顺便说下如果要控制两个RadioButton之间的距离,则设置如下:
android:layout_marginLeft="30px"
效果如下图所示:
赋上源码吧:
main.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/ll" > <RadioGroup android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30px" android:paddingLeft="37dip" android:text="@string/nan" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30px" android:paddingLeft="37dip" android:text="@string/nv" /> </RadioGroup></LinearLayout>
Activity中就默认的就行了。
public class TestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }}
Java代码实现:
main.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/ll" ></LinearLayout>
TestActivity.java:
package com.covics.zfh;import android.app.Activity;import android.graphics.Color;import android.os.Bundle;import android.view.Gravity;import android.widget.FrameLayout.LayoutParams;import android.widget.LinearLayout;import android.widget.RadioButton;import android.widget.RadioGroup;public class TestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LinearLayout ll = (LinearLayout) findViewById(R.id.ll); RadioButton radioBtnMale, radioBtnFemale; LinearLayout.LayoutParams sexParam = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);sexParam.gravity = Gravity.CENTER_VERTICAL; RadioGroup radioGroup = new RadioGroup(this);radioGroup.setLayoutParams(sexParam);radioGroup.setOrientation(RadioGroup.HORIZONTAL);radioBtnMale = new RadioButton(this);// 界面布局宽度,高度LinearLayout.LayoutParams lpWarp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);radioBtnMale.setLayoutParams(lpWarp);radioBtnMale.setText("男");radioBtnMale.setPadding(55, 0, 0, 0);radioBtnMale.setTextColor(Color.parseColor("#999d9c"));radioGroup.addView(radioBtnMale);radioBtnFemale = new RadioButton(this);LinearLayout.LayoutParams femaleParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);radioBtnFemale.setLayoutParams(femaleParams);radioBtnFemale.setText("女");radioBtnFemale.setPadding(55, 0, 0, 0);radioBtnFemale.setTextColor(Color.parseColor("#999d9c"));radioGroup.addView(radioBtnFemale); ll.addView(radioGroup); }}
当然这只是测试小程序,里面有许多不规范的地方,希望大家不要和我学啊,比如在代码中使用了中文字符等。。。
希望这个对大家有帮助,谢谢。
- Android1.6模拟器上RadioGroup的RadioButton和文字的距离很近
- RadioButton和CheckBox的区别,RadioButton&RadioGroup
- RadioGroup和RadioButton的实现
- RadioButton和RadioGroup的使用
- android中RadioGroup点击radiobutton切换radiobutton的背景和文字颜色
- RadioGroup RadioButton的Demo
- android RadioGroup和RadioButton的用法
- 控件RadioGroup、RadioButton和CheckBox的使用
- Android—RadioGroup和RadioButton的使用
- 兔子-RadioButton和RadioGroup的关系
- RadioGroup和RadioButton的简单使用
- RadioGroup的RadioButton图片、文字无法居中解决方法
- 解决RadioGroup的RadioButton图片、文字无法居中
- RadioGroup 和RadioButton制作Tab修改RadioButton的大小
- RadioGroup的RadioButton不居中
- RadioButton上的文字居中显示
- 单项选择功能RadioGroup和RadioButton的使用
- RadioGroup 的 RadioButton 选择改变字体颜色和背景颜色
- 一个dshow filter的code心得。很简单,但写的还不错
- Drawimg 1.图片按比例缩放 2.加水印并设置水印透明度
- 无题
- TypedefViewTest
- Ruby On Rails环境搭建
- Android1.6模拟器上RadioGroup的RadioButton和文字的距离很近
- 索引
- 中国的程序员只能用外国的接口吗?[作为中国的程序员,规划我的2012年]
- adb shell 命令查看android 应用程序 创建的 sqlite 数据库
- Linux编程常用的函数
- 使用位图法判断整形数组是否存在重复
- 2012年春节即将来临
- C++中的this指针
- 找到cmd.exe的替代品console2,用于运行cygwin