2015-05-13 84 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。我已经按照上面的方式工作,但很高兴知道如果我需要动态地这样做,我也可以。谢谢! –

相关问题