Android的布局并排侧控制? [英] Android layout controls side by side?

查看:162
本文介绍了Android的布局并排侧控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个布局,但我不太知道如何正是我想要做的形容。所以我创建了下面的图片来形容我想。

我如何得到微调和的EditText旁边的ImageView像我有在图像中丢失。

下面是我的XML至今。

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
 机器人:layout_width =WRAP_CONTENT
 机器人:layout_height =WRAP_CONTENT>
    < RelativeLayout的
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT>
        <按钮机器人:ID =@ + ID / btnCancel
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentLeft =真
            机器人:文字=取消
            />
        <按钮机器人:ID =@ + ID / btnAdd
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentRight =真
            机器人:文字=添加
            />
    < / RelativeLayout的>
    <&RelativeLayout的GT;
        < ImageView的
            机器人:ID =@ + ID / imgExercise
            机器人:layout_width =50像素
            机器人:layout_height =50像素
            机器人:layout_alignParentTop =真
            机器人:layout_alignParentLeft =真
            />
        <微调
            机器人:ID =@ + ID / spCategory
            机器人:layout_alignParentTop =真
            机器人:layout_alignParentRight =真
            />
        <的EditText
            机器人:ID =@ + ID / etName
            机器人:提示=姓名
            机器人:layout_alignParentTop =真
            机器人:layout_alignParentRight =真
            />
    < / RelativeLayout的>
    <的EditText
        机器人:ID =@ + ID / etDescription
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:行=5
        机器人:重力=顶
        机器人:提示=说明
        />
< / RelativeLayout的>


解决方案

温馨提示-1:

首先,你不需要采取分RelativeLayout的,因为你只能在一个父RelativeLayout的prepare相同的布局。我回来用确切的答案。

温馨提示 - 2:

PX是不是preferable定义的测量,而不是您可以使用畅游,或DP(密度独立像素)(适用于高度的视图/宽)和​​ SP(缩放像素)的字体大小。

解决方案:

 <?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
 机器人:layout_width =FILL_PARENT
 机器人:layout_height =FILL_PARENT
 机器人:填充=5DP>        <按钮机器人:ID =@ + ID / btnCancel
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentLeft =真
            机器人:文字=取消
            />
        <按钮机器人:ID =@ + ID / btnAdd
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentRight =真
            机器人:文字=添加
            />        < ImageView的
            机器人:ID =@ + ID / imgExercise
            机器人:layout_width =100dp
            机器人:layout_height =100dp
            机器人:layout_alignParentLeft =真
            机器人:layout_below =@ + ID / btnCancel
            机器人:SRC =@绘制/图标
            机器人:scaleType =fitXY
            />        <微调
            机器人:ID =@ + ID / spCategory
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_toRightOf =@ + ID / imgExercise
            机器人:layout_below =@ + ID / btnCancel
            机器人:layout_alignTop =@ + ID / imgExercise
            />        <的EditText
            机器人:ID =@ + ID / etName
            机器人:提示=姓名
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_toRightOf =@ + ID / imgExercise
            机器人:layout_below =@ + ID / spCategory
            机器人:layout_alignBottom =@ + ID / imgExercise
            />
    <的EditText
        机器人:ID =@ + ID / etDescription
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:行=5
        机器人:重力=顶
        机器人:提示=说明
        机器人:layout_below =@ + ID / imgExercise
        />
< / RelativeLayout的>

输出:

I am trying to create a layout but I am not too sure how to describe exactly what I want to do. So I have created the below image to describe what I am trying.

I am lost at how to get the spinner and edittext next to the imageview like I have in the image.

Here is my XML so far.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content">
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <Button android:id="@+id/btnCancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:text="Cancel"
            />
        <Button android:id="@+id/btnAdd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="Add"
            />
    </RelativeLayout>
    <RelativeLayout>
        <ImageView
            android:id="@+id/imgExercise"
            android:layout_width="50px"
            android:layout_height="50px"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            />
        <Spinner 
            android:id="@+id/spCategory"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            />
        <EditText 
            android:id="@+id/etName"
            android:hint="Name"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            />
    </RelativeLayout>
    <EditText 
        android:id="@+id/etDescription"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:lines="5"
        android:gravity="top"
        android:hint="Description"
        />
</RelativeLayout>

解决方案

Tips -1:

First of all, you don't need to take sub RelativeLayout because you can prepare the same layout in one parent RelativeLayout only. I am coming back with exact answer.

Tips - 2:

"px" is not preferable to define measurements, instead you can use dip or dp (density independent pixel) (for height/width of view) and sp(scaled pixel) for Font-size.

Solution:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent"
 android:padding="5dp">

        <Button android:id="@+id/btnCancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:text="Cancel"
            />
        <Button android:id="@+id/btnAdd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="Add"
            />

        <ImageView
            android:id="@+id/imgExercise"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/btnCancel"
            android:src="@drawable/icon"
            android:scaleType="fitXY"
            />

        <Spinner 
            android:id="@+id/spCategory"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/imgExercise"
            android:layout_below="@+id/btnCancel"
            android:layout_alignTop="@+id/imgExercise"
            />

        <EditText 
            android:id="@+id/etName"
            android:hint="Name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/imgExercise"
            android:layout_below="@+id/spCategory"
            android:layout_alignBottom="@+id/imgExercise"
            />


    <EditText 
        android:id="@+id/etDescription"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:lines="5"
        android:gravity="top"
        android:hint="Description"
        android:layout_below="@+id/imgExercise"
        />
</RelativeLayout>

Output:

这篇关于Android的布局并排侧控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆