繁体   English   中英

如何将线性布局转换为相对布局

[英]How to convert Linear Layout to Relative Layout

请帮忙。 如果可能的话,我如何将这段代码从LinearLayout转换为相对布局。 或者我可以做些什么使FAB覆盖此代码?

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<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"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:background="@color/white">

    <android.support.v7.widget.Toolbar
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <!-- Framelayout to display Fragments -->

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/emptyScreen">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="@string/label_empty_list"
            android:id="@+id/emptyScreenMsg"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:textColor="@color/gray_text" />
    </RelativeLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/contentScreen" >

        <android.support.v4.widget.SwipeRefreshLayout
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/itemsContainer"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:background="@color/white">

            <ListView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbars="none"
                android:id="@+id/streamListView" />

        </android.support.v4.widget.SwipeRefreshLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:visibility="gone"
            android:background="@color/white"
            android:gravity="center"
            android:id="@+id/streamAdMobCont">

            <com.google.android.gms.ads.AdView
                android:id="@+id/adView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_alignParentBottom="true"
                ads:adSize="BANNER"
                ads:adUnitId="@string/banner_ad_unit_id">
            </com.google.android.gms.ads.AdView>

        </LinearLayout>

    </LinearLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/loadingScreen"
        android:background="@color/white">

        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/progressBar"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/errorScreen"
        android:background="@color/white">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="20dp"
            android:layout_centerVertical="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/error_data_loading"
                android:id="@+id/StreamErrorScreenMsg"
                android:layout_centerVertical="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:gravity="center"
                android:textSize="16dp"
                android:textColor="@color/gray_text" />
        </LinearLayout>

    </RelativeLayout>

</LinearLayout>


<!-- Listview to display slider menu -->

<ListView
    android:id="@+id/list_slidermenu"
    android:layout_width="300dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@color/drawer_divider"
    android:dividerHeight="1dp"
    android:listSelector="@drawable/item_list_row_selector"
    android:background="@color/drawer_bg"
    android:scrollbars="none"
    android:padding="0dp" />

Plaeeaaseeeeeeee帮我取悦eeeeeeeeeee ...谢谢,抱歉我的英语不好:)

只需对每个项目使用android:layoutBelow。

Android的文档中有一个很好的例子

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <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"
        android:background="@color/white"
        android:orientation="vertical"
        tools:context=".MainActivity">

        <android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

        <!-- Framelayout to display Fragments -->

        <RelativeLayout
            android:id="@+id/emptyScreen"
            android:layout_below="@id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent">


            <TextView
                android:id="@+id/emptyScreenMsg"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:text="@string/label_empty_list"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="@color/gray_text" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/contentScreen"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/emptyScreen"
            android:orientation="vertical">

            <android.support.v4.widget.SwipeRefreshLayout xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/itemsContainer"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="@color/white">

                <ListView
                    android:id="@+id/streamListView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scrollbars="none" />

            </android.support.v4.widget.SwipeRefreshLayout>

            <LinearLayout
                android:id="@+id/streamAdMobCont"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@color/white"
                android:gravity="center"
                android:layout_below="@id/itemsContainer"
                android:orientation="vertical"
                android:visibility="gone">

                <com.google.android.gms.ads.AdView
                    android:id="@+id/adView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    ads:adSize="BANNER"
                    ads:adUnitId="@string/banner_ad_unit_id"></com.google.android.gms.ads.AdView>

            </LinearLayout>

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/loadingScreen"
            android:layout_below="@id/contentScreen"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@color/white">

            <ProgressBar
                android:id="@+id/progressBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/errorScreen"
            android:layout_below="@id/loadingScreen"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@color/white">

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:orientation="vertical"
                android:padding="20dp">

                <TextView
                    android:id="@+id/StreamErrorScreenMsg"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_centerVertical="true"
                    android:gravity="center"
                    android:text="@string/error_data_loading"
                    android:textColor="@color/gray_text"
                    android:textSize="16dp" />
            </LinearLayout>

        </RelativeLayout>

    </RelativeLayout>


    <!-- Listview to display slider menu -->

    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/drawer_bg"
        android:choiceMode="singleChoice"
        android:divider="@color/drawer_divider"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/item_list_row_selector"
        android:padding="0dp"
        android:scrollbars="none" />
</android.support.v4.widget.DrawerLayout>

暂无
暂无

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

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