2015-04-01 90 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

相關問題