2013-08-19 68 views
0

我目前的布局看起来如下:如何实现间隔均匀布局

enter image description here

我的XML布局看起来像:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

<TextView 
    android:id="@+id/tvLetter" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_margin="5dp" 
    android:layout_weight="3" 
    android:text="" 
    android:gravity="center" 
    android:textSize="@dimen/letter_size" 
    android:textColor="#FFFFFF" 
    android:background="@drawable/bd" /> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_margin="5dp" 
    android:layout_weight="1" > 

    <Button 
     android:id="@+id/colorButton" 
     android:layout_width="@dimen/btn_action" 
     android:layout_height="@dimen/btn_action" 
     android:layout_centerInParent="true" 
     android:background ="@drawable/colors" 
     android:layout_alignParentLeft="true" /> 

    <Button 
     android:id="@+id/soundButton" 
     android:layout_width="@dimen/btn_action" 
     android:layout_height="@dimen/btn_action" 

     android:layout_centerInParent="true" 
     android:layout_centerHorizontal="true" 
     android:background="@drawable/sound" /> 

    <Button 
     android:id="@+id/eraserButton" 
     android:layout_width="@dimen/btn_action" 
     android:layout_height="@dimen/btn_action" 
     android:layout_alignParentRight="true" 
     android:layout_centerInParent="true" 
     android:background="@drawable/eraser" /> 
</RelativeLayout> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_margin="5dp" 
    android:layout_weight="2" > 

    <ImageView 
     android:id="@+id/ivIcon" 
     android:layout_width="@dimen/letter_icon" 
     android:layout_height="@dimen/letter_icon" 
     android:scaleType="fitXY" 
     android:layout_alignParentLeft="true" 
     android:background="@drawable/zebra" /> 
    <LinearLayout 
     android:id="@+id/actionHolder" 
     android:layout_toRightOf="@+id/ivIcon" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 
     <Button 
      android:id="@+id/wordSound" 
      android:layout_width="@dimen/btn_action" 
      android:layout_height="@dimen/btn_action" 
      android:background="@drawable/sound" /> 
    </LinearLayout> 
</RelativeLayout> 
</LinearLayout> 

@dimen/letter_icon正在根据屏幕上使用不同尺寸尺寸。我试图使其兼容手机和平板电脑(不同大小的屏幕)。如何实现我的布局如下:

enter image description here

比方说,ZEBRA文本是一个TextView里面,声音是一个按钮。

我在想底部ImageView必须在另一个布局内,linearleayout也许?并占用屏幕宽度的3/4的空间。

回答

1

将您的ZEBRASPEAKER按钮垂直放入LinearLayout。设置按钮heightmatch_parentlayout_weight1,你应该有你想要什么

,如果你想发布你的按钮中的宽度容器和ImageView的,width将它们设置为match_parentlayout_weight那里玩。

+0

我是否应该将ZEBRA图片放在另一个布局中,以使图标居中,如果其他图标不同,它不会更改大小? –

+0

你可以,如果你不想玩ImageView的scaleType等。那么布局处理更快的元素,但从现在的1GB手机的其他手,它没有真正的区别。 –

+0

让我感到困惑的是我试图确保它在不同的屏幕设备中显示相同的部分。我想用'@ dimen'将它们全部等于widthXheight' –