2014-02-12 92 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

最需要的是相对布局。 –