Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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 根据屏幕大小缩小字体大小/边距大小?_Android_Xml - Fatal编程技术网

Android 根据屏幕大小缩小字体大小/边距大小?

Android 根据屏幕大小缩小字体大小/边距大小?,android,xml,Android,Xml,我的应用在较大的设备上看起来不错,但在较小的设备上,底部部分会被切断,因为按钮不会根据屏幕大小调整大小 如何使它们根据屏幕大小调整大小,使它们在所有大小上都看起来很好 我在底部有一堆按钮,下面是按钮的代码: <?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:ads="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.an

我的应用在较大的设备上看起来不错,但在较小的设备上,底部部分会被切断,因为按钮不会根据屏幕大小调整大小

如何使它们根据屏幕大小调整大小,使它们在所有大小上都看起来很好

我在底部有一堆按钮,下面是按钮的代码:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:ads="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.uzerjamal.cricketscoremanager.MainActivity" android:background="#E9E9E9" android:orientation="vertical">
 <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" />
  <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1.05" android:orientation="horizontal">
    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical">
        <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="BUTTONeeee" android:layout_marginTop="0dp" android:layout_marginRight="4dp" android:layout_marginLeft="4dp" android:layout_marginBottom="4dp" android:textColor="@android:color/black" android:alpha="0.87" android:backgroundTint="#FF9800" />
        <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="BUTTONeeee" android:layout_marginTop="0dp" android:layout_marginRight="4dp" android:layout_marginLeft="4dp" android:layout_marginBottom="4dp" android:textColor="@android:color/black" android:alpha="0.87" android:backgroundTint="#FF9800" />
        <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="BUTTONeeee" android:layout_marginTop="0dp" android:layout_marginRight="4dp" android:layout_marginLeft="4dp" android:layout_marginBottom="4dp" android:textColor="@android:color/black" android:alpha="0.87" android:backgroundTint="#FF9800" />
        <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="BUTTONeeee" android:layout_marginTop="0dp" android:layout_marginRight="4dp" android:layout_marginLeft="4dp" android:layout_marginBottom="4dp" android:textColor="@android:color/black" android:alpha="0.87" android:backgroundTint="#FF9800" />
        <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="BUTTONeeee" android:layout_marginTop="0dp" android:layout_marginRight="4dp" android:layout_marginLeft="4dp" android:layout_marginBottom="4dp" android:textColor="@android:color/black" android:alpha="0.87" android:backgroundTint="#FF9800" />
    </LinearLayout>
    <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#9E9E9E" android:alpha="0.50" />
    <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical">
        <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="BUTTONeeee" android:layout_marginTop="0dp" android:layout_marginRight="4dp" android:layout_marginLeft="4dp" android:layout_marginBottom="4dp" android:textColor="@android:color/black" android:alpha="0.87" android:backgroundTint="#FF9800" />
        <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="BUTTONeeee" android:layout_marginTop="0dp" android:layout_marginRight="4dp" android:layout_marginLeft="4dp" android:layout_marginBottom="4dp" android:textColor="@android:color/black" android:alpha="0.87" android:backgroundTint="#FF9800" />
        <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="BUTTONeeee" android:layout_marginTop="0dp" android:layout_marginRight="4dp" android:layout_marginLeft="4dp" android:layout_marginBottom="4dp" android:textColor="@android:color/black" android:alpha="0.87" android:backgroundTint="#FF9800" />
        <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="BUTTONeeee" android:layout_marginTop="0dp" android:layout_marginRight="4dp" android:layout_marginLeft="4dp" android:layout_marginBottom="4dp" android:textColor="@android:color/black" android:alpha="0.87" android:backgroundTint="#FF9800" />
        <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="BUTTONeeee" android:layout_marginTop="0dp" android:layout_marginRight="4dp" android:layout_marginLeft="4dp" android:layout_marginBottom="4dp" android:textColor="@android:color/black" android:alpha="0.87" android:backgroundTint="#FF9800" />
  </LinearLayout>
 </LinearLayout>
</LinearLayout>

试试看

1.在应用程序/build.gradle中添加以下依赖项

dependencies {
  compile 'com.intuit.sdp:sdp-android:1.0.4'
}
2。用sdp值替换dp

10sdp on 330dp device = 12dp
10sdp on 420dp device = 14dp
10sdp on 480dp device = 16dp
10sdp on 540dp device = 18dp
例如,如果宽度为10dp,则

 android_layout:width="10dp"
换成

android_layout:width="@dimen/_10sdp" 
如果你想使用java类

Resources res = context.getResources();
float widthInSdp = res.getDimension(R.dimen._10sdp);

int widthInPixels = (int) TypedValue.applyDimension (TypedValue.COMPLEX_UNIT_PX, widthInSdp, res.getDisplayMetrics());
注意:不同设备分辨率上的10sdp

10sdp on 330dp device = 12dp
10sdp on 420dp device = 14dp
10sdp on 480dp device = 16dp
10sdp on 540dp device = 18dp
相应地使用它

试试看

1.在应用程序/build.gradle中添加以下依赖项

dependencies {
  compile 'com.intuit.sdp:sdp-android:1.0.4'
}
2。用sdp值替换dp

10sdp on 330dp device = 12dp
10sdp on 420dp device = 14dp
10sdp on 480dp device = 16dp
10sdp on 540dp device = 18dp
例如,如果宽度为10dp,则

 android_layout:width="10dp"
换成

android_layout:width="@dimen/_10sdp" 
如果你想使用java类

Resources res = context.getResources();
float widthInSdp = res.getDimension(R.dimen._10sdp);

int widthInPixels = (int) TypedValue.applyDimension (TypedValue.COMPLEX_UNIT_PX, widthInSdp, res.getDisplayMetrics());
注意:不同设备分辨率上的10sdp

10sdp on 330dp device = 12dp
10sdp on 420dp device = 14dp
10sdp on 480dp device = 16dp
10sdp on 540dp device = 18dp

相应地使用它

发布你的整个xml文件..嗨,乌泽尔把你的整个xml代码放在Scrollview中,然后没有问题的脸像这样现在没有太多的按钮,我正在重新编码xml,所以上半部分没有任何内容,现在发布你的整个xml文件..嗨,乌泽尔把你的整个xml代码放在Scrollview中,然后没有问题的脸像这样这不是很多,只是一堆按钮,现在我正在重新编码xml,所以上半部分没有任何内容,现在我尝试将其添加到边距中,但当我在android studio中缩小屏幕时,它没有缩小。如何将其添加到布局宽度中?当前设置为匹配@dimen/_10sdp的parentdp在不同屏幕上不相同。android:layout_marginRight=“@dimen/_4sdp”给出的结果与android:layout_marginRight=“4dp”相同。我尝试将其添加到边距中,但在android studio中缩小屏幕时它没有缩小。我如何将其添加到布局宽度中?当前设置为匹配@dimen/_10sdp的parentdp在不同屏幕上不相同。android:layout_marginRight=“@dimen/_4sdp”给出的结果与android:layout_marginRight=“4dp”相同