android,xml按钮布局问题

时间:2011-01-14 11:25:20

标签: android xml button

xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bkgrnd">
<ScrollView
    android:id="@+id/ScrollView01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:isScrollContainer="true"
    android:scrollbars="vertical"
    android:scrollbarAlwaysDrawVerticalTrack="true">
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">     
        <Spinner
            android:id="@+id/Spinner_Table"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:drawSelectorOnTop="true"></Spinner>
         <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:textSize="@dimen/help_text_size"
            android:textStyle="bold"
            android:gravity="center"
            android:id="@+id/Blank"></TextView>
        <TextView  
            android:id="@+id/admintable" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"></TextView>
        <Button 
            android:id="@+id/Logout" 
            android:text="@string/Logout" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"></Button>
        </LinearLayout>
</ScrollView>

我想要做的就是这个活动的最后一个按钮显示在视图的底部。如果我在滚动视图外移动按钮,则会出现错误。我该怎么办?

2 个答案:

答案 0 :(得分:3)

尝试使用RelativeLayout,在开始时有点难,但非常强大。

我认为this就是你想要完成的事情

我现在无法测试它,但RelativeLayout替代方案应如下所示:

<?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:background="@drawable/bkgrnd">
    <Button 
        android:id="@+id/Logout" 
        android:text="@string/Logout" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"></Button>
    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_above="@id/Logout"
        android:isScrollContainer="true"
        android:scrollbars="vertical"
        android:scrollbarAlwaysDrawVerticalTrack="true">
        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">     
            <Spinner
                android:id="@+id/Spinner_Table"
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:drawSelectorOnTop="true"></Spinner>
             <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textSize="@dimen/help_text_size"
                android:textStyle="bold"
                android:gravity="center"
                android:id="@+id/Blank"></TextView>
            <TextView  
                android:id="@+id/admintable" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"></TextView>
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

答案 1 :(得分:1)

Usman你应该做的是实现你的布局层次结构,如下所示

LinearLayout
          |->your ScrollView
          |                  |->Your Linearlayout & then spinner in it etc.etc.(& remove button from this layout)
          |->a new LinearLayout(to hold your button)
                             |->your Logout Button here

你完成了!