Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用XML根据图像大小调整Android组件的大小_Xml_Android_Layout - Fatal编程技术网

如何使用XML根据图像大小调整Android组件的大小

如何使用XML根据图像大小调整Android组件的大小,xml,android,layout,Xml,Android,Layout,我已经使用XML布局创建者在Android中创建了一个自定义图标栏,使用LinearLayout中的RadioGroup(下面包含XML)。RadioGroup中的每个RadioButton都有一个自定义的drawable(选中和未选中状态)作为其android:button属性 线性布局本身位于一个RelativeLayout内,因此它可以显示在屏幕上的任意位置(在本例中,作为侧栏) 可绘制内容的宽度为55像素,所有这些视图的android:layou-width属性为wrap-content

我已经使用XML布局创建者在Android中创建了一个自定义图标栏,使用LinearLayout中的RadioGroup(下面包含XML)。RadioGroup中的每个RadioButton都有一个自定义的drawable(选中和未选中状态)作为其
android:button
属性

线性布局本身位于一个
RelativeLayout
内,因此它可以显示在屏幕上的任意位置(在本例中,作为侧栏)

可绘制内容的宽度为55像素,所有这些视图的
android:layou-width
属性为
wrap-content

当我使这个组件可见时,与屏幕左下角对齐,只有大约四分之三的RadioButton图像宽度可见。将
RelativeLayout
布局\\u宽度设置为
填充\\u父项
可纠正此问题,并显示完整按钮

但是,这意味着按钮组在整个屏幕宽度上使用单击事件

如何使整个按钮显示,并且仅使按钮区域响应单击?硬编码可拉丝的宽度不是一个特别理想的解决方案

<RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content">
    <LinearLayout android:id="@+id/LinearLayout02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_below="@+id/LinearLayout01" android:visibility="invisible">
        <RadioGroup android:id="@+id/RadioGroup01" android:layout_height="wrap_content" android:checkedButton="@+id/RB01" android:layout_width="fill_parent">
            <RadioButton android:id="@+id/RB01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:button="@drawable/DR01"/>
            <RadioButton android:id="@+id/RB02" android:layout_width="fill_parent" android:layout_height="wrap_content" android:button="@drawable/DR02"/>
            <RadioButton android:id="@+id/RB03" android:layout_width="fill_parent" android:layout_height="wrap_content" android:button="@drawable/DR03"/>
            <RadioButton android:id="@+id/RB04" android:layout_width="fill_parent" android:layout_height="wrap_content" android:button="@drawable/DR04"/>
        </RadioGroup>
    </LinearLayout>
    </RelativeLayout>

在dp(密度独立像素)中设置LinearLayout、RadioGroup或RadioButton的宽度可能适合您。根据你上面所说的,我认为应该是布局的宽度。尺寸是“硬编码”的,但它们会随着屏幕的大小进行缩放

因此,xml可能看起来像:

android:layout_width="55dp"

dps的官方文件是

我无法想象为什么另一个答案有6张赞成票,这是完全错误的

尺寸是“硬编码”的,但它们会随着屏幕的大小进行缩放


它们将根据屏幕的密度进行缩放。我非常希望我们可以使用XML中的百分比,而不必对它们进行编码。

为什么?所有安卓系统的宽度都是220dp?