2015-04-01 87 views
1

我有一个LinearLayout,它带有一些在ScrollView中的元素。 现在我希望在屏幕底部有一个按钮(不在滚动视图的底部),它始终显示在前面,同时滚动此布局的其余内容。我怎样才能做到这一点?在LinearLayout中显示按钮始终在滚动时在屏幕的底部

这是我的滚动型:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" 
    android:background="#e2e2e2"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/bgnLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <include 
      layout="@layout/trElement" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="16dp" /> 

     <LinearLayout 
      android:id="@+id/stopslayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_margin="16dp" 
      android:showDividers="middle" 
      android:divider="@drawable/divider"> 

     </LinearLayout> 


    </LinearLayout> 

</ScrollView> 

和多数民众赞成在我加入我现在的按钮的代码部分(总是在滚动型的底部所示):

Button mpbtn = ButtonFactory.makeButton(m, R.string.openMap, R.color.AndroidBlue); 
LinearLayout bgnLayout = (LinearLayout) rootView.findViewById(R.id.bgnLayout); 
bgnLayout.addView(mpbtn); 

我欣赏任何帮助。

+0

为什么不只是在xml的底部添加按钮? – Sid 2015-04-01 08:49:22

回答

3

如果您可以像这样将按钮添加到xml,那么您可以在您的活动课内希望按钮可见和不可见。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/parentLayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      > 
    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fillViewport="true" 
     android:background="#e2e2e2"> 
    ///// 



    </ScrollView> 

    <Button 
    android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
    /> 
    </RelativeLayout> 
+1

谢谢!这适用于我 – unknown 2015-04-01 09:40:43

+1

@ timon93请接受它作为答案然后 – 2015-04-01 09:42:08

+2

你为什么喊? – unknown 2015-04-01 09:47:45

相关问题