【问题标题】:Android - XML button goes missing?Android - XML 按钮不见了?
【发布时间】:2011-01-14 12:27:03
【问题描述】:
<?xml version="1.0" encoding="utf-8"?>
<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="@drawable/bkgrnd">
    <RelativeLayout
        android:id="@+id/RelativeLayout01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
        <ImageView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/ImageView_MenuHeader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/logo"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"></ImageView>
        <TextView
            android:id="@+id/TextView01"
            android:layout_height="wrap_content"
            android:text="@string/admin"
            android:textSize="@dimen/screen_title_size"
            android:shadowDx="0"
            android:shadowDy="0"
            android:shadowRadius="10"
            android:layout_width="wrap_content"
            android:layout_gravity="fill_horizontal|center"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:shadowColor="@android:color/white"
            android:textColor="@color/title_color"></TextView>
        <ImageView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/ImageView_MenuHeader2"
            android:layout_height="wrap_content"
            android:src="@drawable/logo"
            android:layout_gravity="right|center_vertical"
            android:layout_width="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"></ImageView>
    </RelativeLayout>    
    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        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="wrap_content">     
            <Spinner
                android:id="@+id/Spinner_Table"
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:drawSelectorOnTop="true"></Spinner>
             <TextView
                android:layout_width="wrap_content"
                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
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent">  
             <Button 
                android:id="@+id/Logout" 
                android:text="@string/Logout" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"></Button>
    </RelativeLayout>
 </LinearLayout>

上述所有 xml 都在一个线性布局中...问题是当文本视图管理表在应用程序中也获得写入数据时,会显示大量数据...数据显示正常...但是,当用户滚动到屏幕底部时,他们应该会看到注销按钮,但它没有显示?

【问题讨论】:

    标签: android xml button


    【解决方案1】:

    尝试将ScrollView layout_height 设置为60dp 之类的静态值,并将layout_weight 设置为1.0,这将使其在不离开屏幕的情况下扩展到最大。

    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="fill_parent"
        android:layout_height="60dp"
        android:layout_weight="1.0"
        android:isScrollContainer="true"
        android:scrollbars="vertical"
        android:scrollbarAlwaysDrawVerticalTrack="true">
        ...
    </ScrollView>
    

    但是,这应该会导致“注销”按钮一直显示在 ScrollView 下方。

    为了让按钮出现在ScrollView 的底部,请尝试将RelativeLayout 移动到ScrollView 中并将它们嵌套在另一个LinearLayout 中,如下所示:

    <?xml version="1.0" encoding="utf-8"?>
    <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="@drawable/bkgrnd">
        <RelativeLayout
            android:id="@+id/RelativeLayout01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            >
            ... your header views ...
        </RelativeLayout>    
        <ScrollView
            android:id="@+id/ScrollView01"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:isScrollContainer="true"
            android:scrollbars="vertical"
            android:scrollbarAlwaysDrawVerticalTrack="true">
            <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">     
                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content">     
                    ... data you load ...
                </LinearLayout>
                <RelativeLayout
                    android:orientation="vertical"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent">  
                     <Button 
                        android:id="@+id/Logout" 
                        android:text="@string/Logout" 
                        android:layout_width="wrap_content" 
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"></Button>
                </RelativeLayout>
            </LinearLayout>
        </ScrollView>
     </LinearLayout>
    

    【讨论】:

      【解决方案2】:

      一些cmets:

      您不需要像这样定义小部件:

       <Button 
                      android:id="@+id/Logout" 
                      android:text="@string/Logout" 
                      android:layout_width="wrap_content" 
                      android:layout_height="wrap_content"
                      android:layout_alignParentBottom="true"></Button>
      

      你可以这样做:

       <Button 
                      android:id="@+id/Logout" 
                      android:text="@string/Logout" 
                      android:layout_width="wrap_content" 
                      android:layout_height="wrap_content"
                      android:layout_alignParentBottom="true"/>
      

      在我看来,您遇到的问题是 ScrollView 占用了所有剩余空间。

      尝试先用Button 定义RelativeLayout,然后告诉ScrollViewandroid:layout_above RelativeLayout

      【讨论】:

      • 按钮出现在屏幕上,但滚动视图和里面的任何东西都没有
      • 有没有办法将按钮放在滚动视图中,然后告诉按钮始终位于滚动视图的底部,我想要的只是按钮留在滚动视图的底部一直在屏幕上
      猜你喜欢
      • 2013-01-22
      • 1970-01-01
      • 2015-08-17
      • 2021-09-16
      • 2012-01-10
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      • 2013-11-10
      相关资源
      最近更新 更多