让LinearLayout保持在底部的问题 - Android

时间:2011-12-30 07:03:11

标签: android scrollview android-linearlayout gravity

我有一个操作栏固定在顶部,ScrollView包含主要的UI内容,以及我想要保留在屏幕底部的页脚(但我无法做到)。注意:我将布局设置为绿色,另一个红色用于调试。

XML-wise,我有一个基本XML文件,我稍后会填充:

base_layout.xml:

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

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

   <ScrollView
      android:orientation="vertical"
      android:fillViewport="true"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" >

      <LinearLayout
         android:id="@+id/main_menu_layout"
         android:orientation="vertical"
         android:background="#00FF00"  <!-- Note: GREEN -->
         android:layout_width="fill_parent"
         android:layout_height="fill_parent">
      </LinearLayout>
   </ScrollView>
</LinearLayout>

有些活动会有PrefsBar,有些则不会,这就是为什么我在base_layout.xml文件中没有“include layout =”@ layout / prefs_bar“”(见下文)...以及为什么我没有使用RelativeLayout。

在我的活动中,我执行以下操作:

 public void onCreate(Bundle savedInstanceState)
 {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.base_layout);

      LinearLayout emptyMainLayout = (LinearLayout)findViewById(R.id.main_menu_layout);
      LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View menuRowLayout = inflater.inflate(R.layout.tools_kvar, null);
      emptyMainLayout.addView(menuRowLayout);

tools_kvar.xml文件包含:

 <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="#FF0000" >   <!-- Note: RED -->

      <ScrollView
          android:orientation="vertical"
          android:fillViewport="true"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" >

         <TableLayout
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             android:stretchColumns="2">
             < .... ETC .... >
         </TableLayout>
      </ScrollView>

      <include layout="@layout/prefs_bar" />
 </LinearLayout>

第一个问题:为什么too​​ls_kvar.xml(RED)中的主要LinearLayout不能填充所有外部布局?设置了android:layout_height =“fill_parent”!。

prefs_bar.xml(见上文所示)是我需要在屏幕底部修复的内容。它包含:

 <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/prefs_bar_layout"
      android:orientation="horizontal"
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"
      android:background="@color/evengrayer"
      android:gravity="bottom"
      android:layout_gravity="bottom">

      <TextView  ... ETC ...
 </LinearLayout>

目前的结果如下:

Current result

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

尝试使用给定代码块更改tools_kvar.xml以进行滚动视图

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:fillViewport="true"
    android:orientation="vertical" >

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="2" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="test" />
    </TableLayout>
</ScrollView>
相关问题