如何实现均匀间隔的布局

时间:2013-08-19 17:58:31

标签: java android android-layout

我目前的布局如下:

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文本位于文本视图中,声音位于按钮中。

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

1 个答案:

答案 0 :(得分:1)

ZEBRASPEAKER按钮放在垂直LinearLayout中。将按钮“height设置为match_parent”和layout_weight设置为1,您应该拥有自己想要的内容

如果您想在按钮的容器和ImageView之间分配宽度,请将它们width设置为match_parent并在那里使用layout_weight

相关问题