Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.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
Android 安卓:改变按钮';s尺寸根据屏幕尺寸_Android_Xml_Views_Screen Size - Fatal编程技术网

Android 安卓:改变按钮';s尺寸根据屏幕尺寸

Android 安卓:改变按钮';s尺寸根据屏幕尺寸,android,xml,views,screen-size,Android,Xml,Views,Screen Size,我想让我的所有视图在androidxml中根据屏幕大小进行放大。反正我能做到。我不能使用“匹配父项”或“换行”内容 这是相对布局中的一个按钮。我想根据屏幕大小改变它的大小 <Button android:id="@+id/simple_b_1" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout

我想让我的所有视图在androidxml中根据屏幕大小进行放大。反正我能做到。我不能使用“匹配父项”或“换行”内容

这是相对布局中的一个按钮。我想根据屏幕大小改变它的大小

   <Button
        android:id="@+id/simple_b_1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/simple_b_4"
        android:layout_alignLeft="@+id/simple_check"
        android:text="1"
        android:width="66dp" />

已编辑

好的,你们可以在values文件夹和name values文件夹中定义不同的维度文件,比如values(第一个默认文件夹)values-sw480dp,values-sw600dp和values-sw700 用于屏幕大小不超过3.2英寸的值 数值-sw480dp用于3.3英寸至5.7英寸的屏幕尺寸 用于7英寸屏幕尺寸的sw600dp值 values-sw720dp用于屏幕尺寸为10英寸的android将在您这样定义时自动调整所有屏幕

以下是可以在vaules-sw480dp文件夹中为sceen尺寸3.3至5.7英寸定义的dimens文件示例,也可以在不同的值文件夹中为其余屏幕尺寸定义

<?xml version="1.0" encoding="utf-8"?>
 <resources>

   <dimen name="layout_marginBottom">38dp</dimen>
   <dimen name="layout_marginLeft">70dp</dimen>
   <dimen name="layout_marginRight">70dp</dimen>

</resources>

38dp
70dp
70dp
现在,您可以在如下布局中使用它

<Button
                android:id="@+id/mybutton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"

                android:layout_marginBottom="@dimen/layout_marginBottom"<----- these   
                //are the dimens file reference it like that in Layout folder android 
                //will pick automatically

                android:layout_marginRight="@dimen/layout_marginRight"

                android:background="@drawable/frame" />

我的意思是,如果我在nexus 5和nexus 7上使用相同的布局,按钮大小应该相应地有所不同。现在大小是固定的,所以如果我在nexus 5中使用它,它是正确的,但是如果我在nexus 7中使用它,那么按钮的格式就不正确。我使用多个按钮。上面的代码只是我如何在相对布局中定义这些按钮的一个示例。这不会缩放按钮,只会改变它们之间的距离。。。。我想按比例调整按钮的大小。。。但我想我可以用这个尺寸设置按钮的宽度和高度,它可能会工作。。。