2012-12-17 67 views
0

我有一个布局,其中包含查看文本视图,表格以及底部的一些按钮。 我希望按钮始终位于底部,无论桌子的高度如何,因此我将布局更改为相对,这样我就可以做到这一点。未显示TextView和其他元素

但是,这将所有textviews和表格合并为一行。所以我把它们放在RelativeLayout中的一个LinearLayout中,我认为它会解决这个问题。现在的问题是,只有第一个TextView和底部的按钮显示出来。其他一切都缺失。

下面是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" 
    android:layout_margin="4dip" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true"> 

     <TextView 
      android:id="@+id/view_meal_name" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Spaghetti Bolognaise" 
      android:textSize="25sp" /> 

     <TextView 
      android:id="@+id/view_meal_type" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Dinner" 
      android:textSize="16sp" /> 

     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dip" 
      android:layout_marginTop="10dip" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_toLeftOf="@+id/view_day_calories" 
       android:text="@string/calories_label" 
       android:textSize="18sp" /> 

      <TextView 
       android:id="@+id/view_day_calories" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:text="@string/calories_today_value" 
       android:textSize="18sp" /> 
     </RelativeLayout> 

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="2dip" 
      android:layout_marginBottom="10dip" 
      android:background="@color/hr" /> 

     <ScrollView 
      android:id="@+id/scrollView1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <LinearLayout 
       android:id="@+id/linearLayout1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" > 

       <TableLayout 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/tableLayout1" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:layout_marginLeft="10dip" 
        android:layout_marginRight="10dip" 
        android:stretchColumns="0,1,2" > 

        <TableRow 
         android:id="@+id/tableRow1" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" > 

         <TextView 
          android:id="@+id/meal_table_ingred_title" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="@string/ingredient" 
          android:textAppearance="?android:attr/textAppearanceMedium" /> 

         <TextView 
          android:id="@+id/meal_table_quantity_title" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="@string/quantity" 
          android:textAppearance="?android:attr/textAppearanceMedium" /> 

         <TextView 
          android:id="@+id/meal_table_calories_title" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="@string/calories" 
          android:textAppearance="?android:attr/textAppearanceMedium" /> 
        </TableRow> 
       </TableLayout> 
      </LinearLayout> 
     </ScrollView> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:weightSum="1.0" > 

     <Button 
      android:id="@+id/edit_meal_button" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:text="@string/edit_meal_label" /> 

     <Button 
      android:id="@+id/favourite_meal_button" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:text="@string/favourite_meal_label" /> 
    </LinearLayout> 

</RelativeLayout> 

感谢您的帮助!

+1

你试过低于@Shreya沙阿提供解决方案 –

回答

2

变化

<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true"> 

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:orientation="vertical"> 
+1

非常感谢你 –