简体   繁体   English

Android布局

[英]Android layout by layout

How could i achive next one after another layouts position (with height)? 我如何才能达到下一个布局位置(高度)?

在此处输入图片说明

Current code: 当前代码:

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"></ListView>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            android:text="Новая заметка"/>
    </RelativeLayout>
</RelativeLayout>

You can achieve the same layout when you will add "layout_above" property use this code. 使用此代码添加“ layout_above”属性时,可以实现相同的布局。

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

<RelativeLayout
    android:layout_above="@+id/relativeBottom"
    android:layout_width="match_parent"
    android:layout_alignParentTop="true"
    android:layout_height="match_parent">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"></ListView>
</RelativeLayout>

<RelativeLayout
    android:id="@+id/relativeBottom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:text="Новая заметка"/>
    </RelativeLayout>
</RelativeLayout>

I would suggest this 我建议这个

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/myButton">

    </ListView>

    <Button
        android:id="@+id/myButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="22dp"
        android:text="New Note"
        android:layout_marginBottom="5dp"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

Because I don't see the reason to put relative layout insid another relative layout. 因为我看不到将相对布局插入另一个相对布局的原因。

In my understanding of what is needed, there's little need for relative layout at all. 从我对所需内容的理解中,几乎不需要相对布局。 It can be achieved with just LinearLayout , which is less expensive. 只需使用LinearLayout即可实现,该方法更便宜。

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

    <ListView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/myButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="22dp"
        android:text="New Note"
        android:layout_marginBottom="5dp"
        />
</LinearLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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