简体   繁体   中英

How to achieve evenly spaced layout

My current layout looks the following:

在此处输入图片说明

MY XML layout looks like:

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

My @dimen/letter_icon is being used for different sizes based on the screen size. I am trying to make it compatible with both phone and tablet (different size screen). How do I achieve the following in my layout:

在此处输入图片说明

Let's say the ZEBRA text is inside a textview and the sound is in a button.

I am thinking the bottom ImageView has to be inside another layout, linearleayout maybe? and take up 3/4 of the space of the screen width.

Put your ZEBRA and SPEAKER buttons in vertical LinearLayout . Set buttons' height to match_parent and layout_weight to 1 and you should have what you want

and if you want to distribute width among your buttons' container and ImageView, set them width to match_parent and play with layout_weight there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM