2014-02-12 90 views
0

我想要做一個佈局,最後一個按鈕總是在底部,並且如果需要可以滾動。這是我到目前爲止:在底部格式化按鈕的xml

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/gradient_bg" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    > 

<!-- Name Label --> 
<TextView android:id="@+id/NameDesc" 
android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Spot Name:" 
    style="@style/black_text"/> 

<!-- Input Name --> 
<EditText android:id="@+id/inputName" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="5dip" 
    android:layout_marginBottom="15dip" 
    android:singleLine="true" 
    android:capitalize="words"/> 



     <!-- Button Create Product --> 
<Button android:id="@+id/btnDate" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:text="Set Date" 
    android:tag="3" 
    android:onClick="onClick" 
    android:visibility="gone" 
    style="@style/btnStyleBreakerBay"/> 
     <TextView 
    android:id="@+id/txtDate" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Date of Event:" 
    style="@style/black_text" 
    android:visibility="gone"/> 

    <Button android:id="@+id/btnTime" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:text="Set Time" 
    android:tag="4" 
    android:onClick="onClick" 
    android:visibility="gone" 
    style="@style/btnStyleBreakerBay"/> 

       <TextView 
    android:id="@+id/txtTime" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Time of Event:" 
    style="@style/black_text" 
    android:visibility="gone"/> 



    <!--Type in info^ --> 

     <TextView 
     android:id="@+id/txtType" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Event Type:" 
    style="@style/black_text" 
    android:visibility="gone" 
/> 
<Spinner 
    android:id="@+id/spinner_event" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:entries="@array/event_arrays" 
    android:prompt="@string/event_prompt" 
    android:visibility="gone"/> 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Pavement Type:" 
    style="@style/black_text" 
/> 
<Spinner 
    android:id="@+id/spinner_pavement" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:entries="@array/pavement_arrays" 
    android:prompt="@string/pavement_prompt" /> 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Amount of Traffic:" 
    style="@style/black_text" 
/> 
<Spinner 
    android:id="@+id/spinner_traffic" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:entries="@array/traffic_arrays" 
    android:prompt="@string/traffic_prompt" /> 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Environment Type:" 
    style="@style/black_text" 
/> 
<Spinner 
    android:id="@+id/spinner_enviro" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:entries="@array/enviro_arrays" 
    android:prompt="@string/enviro_prompt" /> 

      <Button 
     android:id="@+id/btnCapturePicture" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Take a Picture" 
     android:tag="1" 
     android:onClick="onClick" 
     style="@style/btnStyleBreakerBay"/> 

       <TextView 
       android:id="@+id/txtPreview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Image Preview:" 
     style="@style/black_text" 
     android:visibility="gone"/> 

    <!-- To display picture taken --> 
    <ImageView 
     android:id="@+id/imgPreview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:visibility="gone" /> 


    <FrameLayout 
     android:layout_width="fill_parent" android:layout_height="fill_parent" 
     android:layout_weight="1"> 
    </FrameLayout> 
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> 
         <!-- Button Create Product --> 
<Button android:id="@+id/btnCreate" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Create Spot" 
    android:tag="2" 
    android:onClick="onClick" 
    style="@style/btnStyleBreakerBay"/> 
    </LinearLayout> 


</LinearLayout> 
</ScrollView> 

但我不能得到最後一個按鈕去底部。有人可以幫我嗎?我在這裏嘗試了幾個答案,但似乎沒有任何工作。也許這是因爲我如何設置其他佈局的高度,但我不太確定。

謝謝你在前進,

泰勒

回答

1

你看這是我實現的一些項目,我認爲這將幫助你確定你的佈局, 可以幫助你,並隨時向RelativeLayout的餵我回任何問題

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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" > 
<RelativeLayout 
    android:id="@+id/header" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:background="#FC9" 
    android:gravity="center" > 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:text="Fixed Header" 
     android:textColor="#000" 
     android:textSize="20sp" /> 
</RelativeLayout> 
<!-- Footer aligned to bottom --> 
<RelativeLayout 
    android:id="@+id/footer" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:background="#FC0" 
    android:gravity="center" > 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:text="Fixed Footer" 
     android:textColor="#000" 
     android:textSize="20sp" /> 
</RelativeLayout> 
<ScrollView 
    android:id="@+id/scrollableContents" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_above="@id/footer" 
    android:layout_below="@id/header" 
    android:background="#005" > 
</ScrollView> 
</RelativeLayout> 
+0

謝謝!這種佈局真的很有幫助!我可能會通過我所有的XML佈局,並用它替換它們。它確實比我所做的更好地組織它! – TylerM

+0

:)不客氣 –

1

我想我能想到的最好的辦法是使用RelativeLayout。它有成員android:layout_alignParentBottom="true",你可以在你的Button中使用RelativeLayout。這將始終保持在最底層。

+0

我只能窩成linearlayout並只包含在相對的按鈕?還是整個事情都需要相對? – TylerM

+0

最需要的是相對佈局。 –