Tabcontent应始终与RelativeLayout对齐

时间:2015-09-07 07:47:12

标签: android xml android-layout

我在LinearLayout中有三个3相对布局。 First Relative布局包含Tabhost。 所有Tabhost内容应始终在第二个RelativeLayout上方对齐。 问题是内容总是被视为第3和第2相对布局的背后。 它如何能够始终高于第二个RelativeLayout?

enter image description here

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

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:background="@color/background_floating_material_dark">

    <android.support.v4.app.FragmentTabHost
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFFFFFFF">

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="top"
                android:gravity="top"/>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingTop="62dp"/>

    </android.support.v4.app.FragmentTabHost>

    <RelativeLayout
        android:id="@+id/rel_for_sip_active"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#19c031"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:layout_above="@+id/relativeLayout"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Online"
            android:id="@+id/online_offline"
            android:layout_marginLeft="39dp"
            android:layout_marginStart="39dp"
            android:textColor="#afafaf"
            android:textStyle="bold"
            android:layout_marginTop="15dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="On going call....."
            android:id="@+id/textView12"
            android:layout_marginLeft="39dp"
            android:layout_marginStart="39dp"
            android:textColor="@color/white"
            android:textStyle="bold"
            android:visibility="gone"
            android:layout_marginTop="15dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="00:00:00"
            android:id="@+id/callcounter"
            android:textColor="#afafaf"
            android:textStyle="bold"/>

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/unmute"
            android:onClick="Unmute"
            android:src="@mipmap/ic_action_mute"
            android:visibility="gone"
            android:background="@android:color/transparent"
            android:layout_marginRight="26dp"
            android:layout_marginEnd="26dp"/>

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/mute"
            android:onClick="Mute"
            android:src="@mipmap/ic_action_mute_active"
            android:background="@android:color/transparent"
            android:visibility="gone"
            android:layout_marginRight="26dp"
            android:layout_marginEnd="26dp" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/demute"
            android:src="@mipmap/ic_action_mute_inactive"
            android:background="@android:color/transparent"
            android:visibility="visible"
            android:layout_marginRight="26dp"
            android:layout_marginEnd="26dp"/>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:background="@color/background_floating_material_dark"
        style="@style/Theme.Callbox"
        android:id="@+id/relativeLayout"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <ImageView
            android:id="@+id/action_bar_addtarget"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:scaleType="fitCenter"
            android:src="@drawable/ic_action_call"
            android:background="@drawable/bg_btn_btm_actionbar"
            android:visibility="visible"
            android:onClick="Call" />

        <ImageView
            android:id="@+id/action_bar_addtarget_end"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:scaleType="fitCenter"
            android:background="@drawable/bg_btn_btm_actionbar"
            android:src="@drawable/ic_action_end_call"
            android:visibility="gone"
            android:onClick="endCall" />

        <ImageView
            android:id="@+id/action_bar_dialpad"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:scaleType="fitCenter"
            android:src="@drawable/ic_action_dialer"
            android:background="@drawable/bg_btn_btm_actionbar"
            android:visibility="visible"
            android:onClick="showDialpad"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" />

        <ImageView
            android:id="@+id/action_bar_filter"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:contentDescription="@string/dummy"
            android:background="@drawable/bg_btn_btm_actionbar"
            android:visibility="visible"
            android:scaleType="fitCenter"
            android:onClick="showCallResult"
            android:src="@drawable/ic_action_process_save"
            android:layout_below="@+id/action_bar_addtarget_end"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

    </RelativeLayout>

</RelativeLayout>

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/relativeLayout"
    android:visibility="gone"
    android:id="@+id/fl_slide_pop">
</FrameLayout>

1 个答案:

答案 0 :(得分:1)

您的设计中有几件事情很糟糕。 你有太多的布局,我试图尽可能多地删除它们。

此外,您还有3个用于静音/取消静音/静音的ImageButtons,其中只有一个可以通过编程方式进行设置。

如果你没有对它进行优化,那么对于一个视图进行充气就会非常重要。

SDK中有一个tool可帮助您查看布局层次结构,以便了解如何对其进行优化 您可以尝试做一些更简单的事情,例如:

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


    <!-- here is the bottom layout which contains your 3 buttons -->
    <LinearLayout
        android:id="@+id/third_layout"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_alignParentBottom="true"
        android:background="#ff0000"
        android:orientation="horizontal"
        android:weightSum="3">

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

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

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


    </LinearLayout>


    <!-- Here is the equivalent of the 2nd relative layout, but you just have to show a image 
    button or a Text view, you don't have to use another relative layout -->
    <ImageButton
        android:id="@+id/mute"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_above="@id/third_layout"
        android:background="@android:color/holo_green_dark"
        android:src="@android:drawable/ic_btn_speak_now" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_above="@id/third_layout"
        />

    <!-- finally the 1st layout which is above the second to the top of its parent -->

    <android.support.v4.app.FragmentTabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/mute"
        android:layout_alignParentTop="true"
        android:background="@android:color/holo_blue_bright">

        <!-- TAB Widget -->

    </android.support.v4.app.FragmentTabHost>


</RelativeLayout>

我鼓励您使用较少的布局以使应用程序更流畅。