Android layout Android中不同屏幕密度单选按钮之间的间距
我试图为一个调查问题做一个布局,它在我的设备上运行良好,但在屏幕分辨率更好的设备上,单选按钮文本之间的间距会减小 我尝试过创建不同的尺寸,但我不确定如何根据不同的尺寸调整边距 请建议我需要创建的swXXX文件夹的屏幕大小值,以及我定义的尺寸的比例因子 谢谢Android layout Android中不同屏幕密度单选按钮之间的间距,android-layout,Android Layout,我试图为一个调查问题做一个布局,它在我的设备上运行良好,但在屏幕分辨率更好的设备上,单选按钮文本之间的间距会减小 我尝试过创建不同的尺寸,但我不确定如何根据不同的尺寸调整边距 请建议我需要创建的swXXX文件夹的屏幕大小值,以及我定义的尺寸的比例因子 谢谢 enter code here <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com
enter code here
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/tv_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="How often do you use it?"
android:textSize="15sp" />
<RadioGroup
android:id="@+id/rg_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tv_1"
android:layout_below="@+id/tv_1" >
<RadioButton
android:id="@+id/rb_once"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="15dp"
android:button="@drawable/radio_btn"
android:checked="true"
android:text="Once" />
<RadioButton
android:id="@+id/rb_daily"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/rb_once"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:button="@drawable/radio_btn"
android:text="Daily" />
<RadioButton
android:id="@+id/rb_weekly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/rb_daily"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:button="@drawable/radio_btn"
android:text="Weekly" />
<RadioButton
android:id="@+id/rb_monthly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/rb_weekly"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:button="@drawable/radio_btn"
android:text="Monthly" />
</RadioGroup>
<ImageView
android:id="@+id/fb_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:src="@drawable/facebook_share" />
<ImageView
android:id="@+id/history"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/fb_share"
android:layout_marginLeft="10dp"
android:src="@drawable/history" />
<ImageView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/fb_share"
android:layout_marginRight="10dp"
android:src="@drawable/info" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/fb_share"
android:layout_below="@+id/rg_1"
android:layout_centerHorizontal="true" >
<Button
android:id="@+id/send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="@drawable/red_btn"
android:fontFamily="Roboto-Italic"
android:text="SAVE"
android:textColor="#ffffff" />
</RelativeLayout>
</RelativeLayout>
在此处输入代码
您需要为目标设备创建swXXXX文件夹的值。i、 e如果目标平板电脑的最小宽度为600,则需要创建值-sw600,以此类推
在布局文件中,将RadioButton的声明更改如下:
<RadioButton
android:id="@+id/rb_once"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/left_margin"
android:layout_marginTop="@dimen/top_margin"
android:button="@drawable/radio_btn"
android:checked="true"
android:text="Once" />
并在值swXXXX下维护特定于每个目标维度的dimen.xml,维度键具有相同的名称,但对应于各个维度的值。例:
values/
<dimen name="left_margin">5dp</dimen>
<dimen name="left_margin">10dp</dimen>
values-sw600/
<dimen name="left_margin">20dp</dimen>
<dimen name="left_margin">40dp</dimen>
值/
5dp
10dp
价值观-sw600/
20dp
40dp
谢谢您的回复。如果我们不是针对平板电脑,那么我们能制造values-sw160、values-sw240、values-sw320和values-sw480吗?从技术上讲,这应该是可行的!但我还没有测试你的场景。请注意,sw仅支持版本为3.2+的Android操作系统。