2014-02-11 53 views
0

我需要这样的结果。ScrollView with Button

enter image description here

我的XML

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

    <include layout="@layout/background_water"/> 

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

     <ScrollView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"> 

      <include layout="@layout/finish_order_content"/> 

     </ScrollView> 

     <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

      <Button 
        android:id="@+id/sendOrder" 
        android:text="Оформить заказ" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:layout_marginLeft="4dp" 
        android:layout_marginRight="4dp" 
        android:layout_marginBottom="8dp" 
        android:background="@drawable/btn_orange"/> 

     </RelativeLayout> 

    </LinearLayout> 

</RelativeLayout> 

如果滚动型有一个很长的内容,那么按钮不显示(我看到的只是滚动)。如何解决它?

+0

你可以把这些线性布局和重量 – Burusothman

回答

0

你可以做下面的事情。将android:layout_above="@id/sendOrder"添加到ScrollView以使其出现在按钮上方并将其高度设置为fill_parent以填充可用空间。

我不确定<include layout="@layout/background_water"/>应该如何工作,因为您没有将它包含在上面的图片中。

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

    <Button 
     android:id="@+id/sendOrder" 
     android:text="Оформить заказ" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_marginLeft="4dp" 
     android:layout_marginRight="4dp" 
     android:layout_marginBottom="8dp" 
     android:background="@drawable/btn_orange"/> 

    <include layout="@layout/background_water"/> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@id/sendOrder"> 

     <include layout="@layout/finish_order_content"/> 

    </ScrollView> 

</RelativeLayout> 
0
// try this way 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <include layout="@layout/background_water"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <include layout="@layout/finish_order_content"/> 

    </ScrollView> 
    </LinearLayout> 

    <Button 
     android:id="@+id/sendOrder" 
     android:text="Оформить заказ" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="4dp" 
     android:layout_marginRight="4dp" 
     android:layout_marginBottom="8dp" 
     android:background="@drawable/btn_orange"/> 

</LinearLayout> 
0

试试这个:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

<include layout="@layout/background_water"/> 
<FrameLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

<ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" > 

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

    <include layout="@layout/finish_order_content"/> 

    </LinearLayout> 
    </ScrollView> 

     <LinearLayout 
     android:id="@+id/footer" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:layout_marginBottom="0dp" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:padding="5dp" > 

     <Button 
       android:id="@+id/sendOrder" 
       android:text="Оформить заказ" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_horizontal|center_vertical" 
       android:layout_marginLeft="4dp" 
       android:layout_marginRight="4dp" 
       android:layout_marginBottom="8dp" 
       android:background="@drawable/btn_orange"/> 

    </LinearLayout> 
</FrameLayout> 

</LinearLayout> 
0

下面应该工作。我冒昧删除不必要的视图。不知道background_water究竟是什么,但如果它应该被用作背景,只需删除你的include(以及我添加到ScrollView中的android:layout_below部分),并在主RelativeLayout上使用android:background。

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

    <include layout="@layout/background_water" 
     android:id="@+id/include_layout"/> 

    <Button 
     android:id="@+id/sendOrder" 
     android:text="Оформить заказ" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_marginLeft="4dp" 
     android:layout_marginRight="4dp" 
     android:layout_marginBottom="8dp" 
     android:background="@drawable/btn_orange"/> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@id/sendOrder" 
     android:layout_below="@id/include_layout"> 

     <include layout="@layout/finish_order_content"/> 

    </ScrollView> 

</RelativeLayout> 
0

只需尝试一次,将以下代码放入xml文件并查看其预览。 我希望这将帮助ü或至少提供U A线索:

<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" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" > 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/button" 
     android:layout_marginBottom="10dip" 
     android:background="#bb9789" > 
    </ScrollView> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:background="#ff6790" 
     android:gravity="center" 
     android:text="Button" /> 

</RelativeLayout> 

activity_vertical_margin

16dip

相关问题