2015-05-13 85 views
1

這是一種延續,我想在離線時在屏幕底部(在底部工具欄下方)獲取警告文本。當在脫機模式下看起來是正確的:Android製作底部工具欄不能移動到佈局頂部

When offline mode selected

然而,當我隱藏離線模式下,它會彈出佈局的頂部,像這樣的(我想顯示隱藏的一切):

enter image description here

我試着將底部工具欄設置爲android:layout_alignParentBottom="true",當我隱藏帶有TextView的RelativeLayout(離線模式)時,它不會彈出到頂部,但是當我不隱藏離線模式時,它們會相互覆蓋。

也許很容易的人多一點經驗與Android UI比我的XML佈局目前看起來是這樣的:

<RelativeLayout 
    android:id="@+id/mainLyt" 
    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"> 

    <ScrollView 
     android:id="@+id/formScrollView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentTop="true" 
     android:layout_above="@+id/bottomBar" > 
     <LinearLayout 
      android:id="@+id/formLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="10dp" 
      android:paddingTop="15dp" 
      android:paddingRight="10dp" 
      android:paddingBottom="15dp" 
      android:orientation="vertical" > 
     </LinearLayout> 

    </ScrollView> 

    <RelativeLayout 
     android:id="@+id/bottomBar" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:orientation="horizontal" 
     android:layout_above="@+id/bottomOffline" 
     android:background="@color/form_toolbar"> 

     <ImageButton 
      android:id="@+id/btnPrev" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:onClick="btnPrevClicked" 
      android:layout_alignParentLeft="true" 
      android:focusableInTouchMode="false" 
      android:background="?android:attr/selectableItemBackground" 
      android:src="@drawable/toolbar_prev" 
      android:padding ="8dp" 
      /> 

     <ImageButton 
      android:id="@+id/btnIndex" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/btnPrev" 
      android:onClick="btnIndexClicked" 
      android:focusableInTouchMode="false" 
      android:background="?android:attr/selectableItemBackground" 
      android:src="@drawable/toolbar_index" 
      android:padding ="8dp" 
      /> 

     <ImageButton 
      android:id="@+id/btnValidation" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/btnIndex" 
      android:onClick="btnValidationClicked" 
      android:focusableInTouchMode="false" 
      android:background="?android:attr/selectableItemBackground" 
      android:src="@drawable/toolbar_validate" 
      android:padding ="8dp" 
      /> 

     <ImageButton 
      android:id="@+id/btnNext" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:onClick="btnNextClicked" 
      android:focusableInTouchMode="false" 
      android:background="?android:attr/selectableItemBackground" 
      android:src="@drawable/toolbar_next" 
      android:padding ="8dp" 
      /> 
    <!-- Some Buttons --> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/bottomOffline" 
     android:layout_width="match_parent" 
     android:layout_height="34dp" 
     android:layout_alignParentBottom="true" 
     android:background="@color/orangelight" 
     android:gravity="center_horizontal"> 

     <TextView 
      android:id="@+id/offline" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:focusableInTouchMode="false" 
      android:text="OFFLINE MODE" 
      android:textStyle="bold" 
      android:textColor="@color/white" 
      android:padding ="8dp" 
      /> 
    </RelativeLayout> 

</RelativeLayout> 

謝謝!

回答

0

嘗試包裹在的LinearLayout底部的觀點,並從兩個嵌套觀點刪除對齊領域

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_alignParentBottom="true" 
android:orientation="vertical"> 

<RelativeLayout 
    android:id="@+id/bottomBar" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:orientation="horizontal" 
    android:background="@color/form_toolbar"> 

    <ImageButton 
     android:id="@+id/btnPrev" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="btnPrevClicked" 
     android:layout_alignParentLeft="true" 
     android:focusableInTouchMode="false" 
     android:background="?android:attr/selectableItemBackground" 
     android:src="@drawable/toolbar_prev" 
     android:padding ="8dp" 
     /> 

    <ImageButton 
     android:id="@+id/btnIndex" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/btnPrev" 
     android:onClick="btnIndexClicked" 
     android:focusableInTouchMode="false" 
     android:background="?android:attr/selectableItemBackground" 
     android:src="@drawable/toolbar_index" 
     android:padding ="8dp" 
     /> 

    <ImageButton 
     android:id="@+id/btnValidation" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/btnIndex" 
     android:onClick="btnValidationClicked" 
     android:focusableInTouchMode="false" 
     android:background="?android:attr/selectableItemBackground" 
     android:src="@drawable/toolbar_validate" 
     android:padding ="8dp" 
     /> 

    <ImageButton 
     android:id="@+id/btnNext" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:onClick="btnNextClicked" 
     android:focusableInTouchMode="false" 
     android:background="?android:attr/selectableItemBackground" 
     android:src="@drawable/toolbar_next" 
     android:padding ="8dp" 
     /> 
    <!-- Some Buttons --> 
</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/bottomOffline" 
    android:layout_width="match_parent" 
    android:layout_height="34dp" 
    android:background="@color/orangelight" 
    android:gravity="center_horizontal"> 

    <TextView 
     android:id="@+id/offline" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:focusableInTouchMode="false" 
     android:text="OFFLINE MODE" 
     android:textStyle="bold" 
     android:textColor="@color/white" 
     android:padding ="8dp" 
     /> 
</RelativeLayout> 

+0

更好 - 現在我可以看到其餘的字段,但它仍然彈出到頂部...並且「離線模式」根本不顯示...當處於離線模式時 –

+0

whops,設置LinearLayout的高度到「wrap_content」 – leibreichb1

+0

太棒了。那就是訣竅。我需要查看「wrap_content」和「parent_match」之間的區別。但它像一種魅力。 –

0

使用Java,當您處於在線模式時,我們可以編程方式將視圖設置爲在底部對齊。可以在用於刪除脫機欄的代碼之後放置以下代碼。 (由於你沒有發佈你的Java,我不能更具體)我假設變量bottomBarRelativeLayout類型,並通過findViewById(R.id.bottomBar分配。

RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)bottomBar.getLayoutParams(); 
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
bottomBar.setLayoutParams(params); 

這是什麼應該做的是設置ALIGN_PARENT_BOTTOM標誌(android:layout_alignParentBottom="true"在XML)底欄上,這樣它會留在底部,離線條被刪除後也。所以,如果你馬上添加刪除脫機欄後,它會更新視圖,並顯示欄正確

+0

T3KBAU5。我已經按照上面的方式工作,但很高興知道如果我需要動態地這樣做,我也可以。謝謝! –

相關問題