0

我有我的布局问题我想垂直排列图像按钮,我希望它有不同的屏幕尺寸相同的外观这里是一个打印屏幕http://flic.kr/p/fwEZn1Android:图像按钮布局垂直,将适合所有屏幕尺寸

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/chalk" 
android:gravity="center|fill_vertical" 
android:orientation="vertical" > 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="1000dp" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="104dp" > 

    <ImageButton 
     android:id="@+id/m" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="62dp" 
     android:layout_weight="1.30" 
     android:background="@android:color/transparent" 
     android:contentDescription="exam schedule button" 
     android:onClick="ex" 
     android:src="@drawable/exam" /> 

    <ImageButton 
     android:id="@+id/cl" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="60dp" 
     android:background="@android:color/transparent" 
     android:contentDescription="classes button" 
     android:onClick="cl" 
     android:src="@drawable/list1" /> 

    <ImageButton 
     android:id="@+id/lec" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.24" 
     android:background="@android:color/transparent" 
     android:contentDescription="lecture section button" 
     android:onClick="lc" 
     android:src="@drawable/sylla" /> 

    <ImageButton 
     android:id="@+id/gr" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="20dp" 
     android:layout_weight="3.36" 
     android:background="@android:color/transparent" 
     android:contentDescription="group button" 
     android:onClick="gr" 
     android:src="@drawable/group" /> 
     </LinearLayout> 

    <LinearLayout 
    android:id="@+id/linearLayout2" 
    android:layout_width="1000dp" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/linearLayout1" 
    android:layout_marginTop="123dp" > 

    <ImageButton 
     android:id="@+id/kl" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="74dp" 
     android:layout_weight="0.69" 
     android:background="@android:color/transparent" 
     android:contentDescription="calendar button" 
     android:onClick="kl" 
     android:src="@drawable/calendar" /> 

    <ImageButton 
     android:id="@+id/d" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignTop="@+id/pd" 
     android:layout_marginRight="84dp" 
     android:layout_weight="0.38" 
     android:background="@android:color/transparent" 
     android:contentDescription="Schedule button" 
     android:onClick="sk" 
     android:src="@drawable/sked" /> 

    <ImageButton 
     android:id="@+id/pd" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/button1" 
     android:layout_alignTop="@+id/an" 
     android:layout_weight="0.16" 
     android:background="@android:color/transparent" 
     android:contentDescription="podcast button" 
     android:onClick="pd" 
     android:src="@drawable/podcast" /> 

    <ImageButton 
     android:id="@+id/an" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/kl" 
     android:layout_marginLeft="60dp" 
     android:layout_toRightOf="@+id/kl" 
     android:layout_weight=".92" 
     android:background="@android:color/transparent" 
     android:contentDescription="announcement button" 
     android:onClick="an" 
     android:src="@drawable/announce" /> 
    </LinearLayout> 
    <ImageButton 
    android:id="@+id/button1" 
    android:layout_width="53dp" 
    android:layout_height="40dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_marginBottom="106dp" 
    android:layout_marginLeft="342dp" 
    android:layout_weight="0.38" 
    android:background="@android:color/transparent" 
    android:contentDescription="logout button" 
    android:onClick="logout" 
    android:src="@drawable/logout" 
    android:text="Logout" /> 
</RelativeLayout> 

所以基本上我想修复图像按钮的排列。我怎样才能做到这一点?我是否需要调整每个可绘制文件夹的图像大小?

回答

0

当你说“看”时,你的意思是所有屏幕尺寸的尺寸是否相同?一种可能的方法来做到这一点,将设置ImageButton的在你的XML:

scaleType="centerInside" 

,并设置从您的图片按钮,所有的权重为1

layout_weight="1" 

,如果你想设置每个按钮垂直,申报你的LinearLayout

android:orientation="vertical" 

顺便说一句,这是百达一个很好的做法,为每一个绘制,以适应多屏设置不同的图像。

0

有一个简单的解决方案。我发现你希望布局在所有屏幕尺寸上看起来都一样,但是你使用硬编码的值作为layout_height,margin,padding等。为此,在values文件夹中使用dimens.xml。指定所有屏幕的值,在您的资源文件夹中创建这些文件夹:

values-small 
    values-normal(The default values folder is values-normal)  
    values-large 
    values-xlarge(You can use values-sw600 for tablets after Android 3.2) 

在所有这些文件夹的创建,您可以指定边距,高度,宽度,填充等,在DP dimens.xml,你甚至可以指定字体大小。希望这可以帮助!