2015-09-07 71 views
1

我在LinearLayout中有三个3相对布局。 第一个相对布局包含Tabhost。 所有Tabhost内容应始终与第二个RelativeLayout对齐。 问题是内容始终被视为在第三和第二个相对布局之后。 它如何始终在第二个RelativeLayout之上进行创建?Tabcontent应始终与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> 

+0

您的线性布局仍然开放 – Mohit

回答

1

几件事情在你的设计是坏的。 你有太多的布局,我试图尽可能删除其中的一些。

此外,您还有3个ImageButtons用于静音/取消静音/ demute,其中只有一个可以通过编程方式更改。

如果你没有对它进行优化,膨胀一个视图是一种沉重的android。

有一个tool进入,帮助你看到你的布局层次结构,以了解如何优化它 你可以尝试做一些简单的像这样的例子在SDK:

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

我鼓励你使用更少的布局以获得更流畅的应用程序。

+0

非常感谢您的回答,从现在起非常有用的提示将使用它。顺便说一句,只是为了添加一个问题,你如何将tabwidget放在顶部?而不是在底部? – woninana

相关问题