2015-09-07 68 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

相關問題