2011-12-30 84 views
0

我有一个固定在顶部的操作栏,一个包含主UI界面的ScrollView和一个想保留在屏幕底部的页脚(但我无法做)。注:我做了一个布局绿色和另一个红色的调试。让LinearLayout留在底部的问题 - Android

XML明智的,我有一个基础的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> 

一些activitys将有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> 

第一个问题:为什么在tools_kvar.xml没有主要的LinearLayout(RED)填充所有的外部布局? 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

任何帮助将不胜感激!

+0

为什么不使用'相对layout'而不是和应用'机器人:layout_alignParentBottom =“真”'属性? – Ghost 2011-12-30 07:09:52

+0

某些活动将具有PrefsBar,有些活动不会,这就是为什么我没有在base_layout.xml文件(参见下文)中包含“include layout =”@ layout/prefs_bar“”......为什么我没有不使用RelativeLayout。我想,解决方案是创建两个“base_layout.xml”文件,一个带有prefs栏,另一个没有。 – zundi 2011-12-30 07:12:07

+0

是的。这似乎是一个可能的解决方案。我没有看到使用线性布局将PrefsBar固定到底部的方法。但您希望实现的用户界面可以使用相对布局进行设置。如果你能详细说明为什么你想要坚持线性布局和滚动视图,我认为这会很有帮助。 – Ghost 2011-12-30 07:18:02

回答

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> 
+0

刚刚尝试过,但没有改变。我想我只会去为RelativeLayout = [ – zundi 2011-12-30 12:26:40