2015-09-07 5 views
1

У меня есть три 3 Относительная компоновка в LinearLayout. Первая относительная компоновка содержит Tabhost. Все содержимое Tabhost должно быть выровнено над вторым RelativeLayout в любое время. Проблема заключается в том, что контент всегда рассматривается как за 3-й и 2-й относительной компоновкой. Как это сделать, как всегда, над вторым 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 для отключения/включения/отключения, когда только один может быть установлен программно изменен.

Надуть вид тяжело на андроид, если вы его не оптимизировали.

Существует 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

Смежные вопросы