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

时间:2016-03-08 18:18:23

标签: java android android-studio

请帮忙。我如何将此代码从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帮助我pleaseeeeeeeeee ...感谢和抱歉我的英语不好:)

2 个答案:

答案 0 :(得分:0)

为每个项目使用android:layoutBelow。

Android的文档有good example

答案 1 :(得分:0)

<?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>
相关问题