2017-02-22 168 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

相關問題