对齐控制 [英] Aligning Controls

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

问题描述

我只是在浪费时间这个问题,因为我不知道如何正确地做到这一点。基本上,我想有一个自定义输入视图,用户可以得出什么,他希望与他/她的手指,在它下面,我希望把2(或者更多)的按钮,我不想重复上自定义视图的顶部。因为我试图避免硬编码的宽度和高度,有没有什么办法来指定的按钮应该换到自己的内容和自定义视图应该占据,余下的高度?因为我希望所有按钮具有相同的高度,我想,他们取了一个高度为基准应该以某种方式工作...

I'm just wasting time with this, because I have no idea how to do it properly. Basically, I want to have a custom input view, where the user can draw whatever he wants with his / her finger and, below it, I want to place 2 (or maybe more) buttons, which I don't want to overlap on top of the custom view. Because I'm trying to avoid hardcoding widths and heights, is there any way to specify that the buttons should wrap to their contents and the custom view should occupy the remaining height? Since I expect all buttons to have the same height, I guess that taking the height of one of them as a reference should work somehow...

下面是我当前的布局:

<RelativeLayout 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"
    tools:context=".MainActivity" >

    <com.example.myapp.DrawView
        android:id="@+id/drawView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

    <Button
        android:id="@+id/buttonSave"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="@string/save" />

    <Button
        android:id="@+id/buttonQuery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="@string/query" />

</RelativeLayout>

它实际上是有可能实现我想要什么容易,而无需破解它讨厌的方式?

Is it actually possible to achieve what I want easily, without having to hack it in nasty ways?

推荐答案

将上述自定义视图按钮

<RelativeLayout 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"
    tools:context=".MainActivity" >

   <Button
        android:id="@+id/buttonSave"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="@string/save" />

    <Button
        android:id="@+id/buttonQuery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="@string/query" />

    <com.example.myapp.DrawView
        android:id="@+id/drawView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" 
        android:layout_above="@id/buttonSave" />

</RelativeLayout>

如果您不能确定有关按钮的高度等于你就必须包装他们另一个布局(如的LinearLayout ),然后将自定义的查看的包装之上。

If you aren't sure about the height of the Buttons being equal you would have to wrap them in another layout(like LinearLayout) and then place the custom View above that wrapper.

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

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