开发者

android, xml button layout issue

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:l开发者_运维知识库ayout_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>

All I want to do is the last button on this activity to be displayed at the bottom of the view. If I move the button outside the scroll view I get an error. What should I do?


Try using a RelativeLayout, a little hard at the begining but very powerful.

Also I think this is what you try to accomplish

I can't test it right now, but the RelativeLayout alternative should look like this:

<?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>


Well Usman what you should do is implement your layout hierarchy as below

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

and you are done!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜