2017-02-22 201 views
1

我的应用在较大的设备上看起来不错,但在较小的设备上,底部会被切断,因为按钮不会根据屏幕大小调整大小。根据屏幕尺寸缩小字体大小/边距大小?

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

我有在底部的一堆按钮和这里的按钮代码:

<?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> 
+0

发表您的整个XML文件.. –

+0

嗨Uzer把你的整个XML代码,滚动型则没有问题,面对这样的 –

+0

https://hastebin.com/oyoxajipom.xml – Uzer

回答

0

尝试sdp library

添加按照您的应用程序依赖/的build.gradle

dependencies { 
    compile 'com.intuit.sdp:sdp-android:1.0.4' 
} 

2.用sdp值替换dp

例如如果您在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()); 

注:在不同的设备reslutions 10sdp

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

使用它相应

+0

我试图将此添加到边距,但它并没有缩小,当我缩小在Android工作室的屏幕 如何将此添加到布局宽度?它目前设置为匹配父母 – Uzer

+0

@ dimen/_10sdp的Dps在不同屏幕上不一样。 – Pehlaj

+0

android:layout_marginRight =“@dimen/_4sdp”给出与android:layout_marginRight =“4dp”相同的结果 – Uzer