代码之家  ›  专栏  ›  技术社区  ›  Niall Paterson

强制android比它滚动得更远

  •  0
  • Niall Paterson  · 技术社区  · 13 年前

    正如你所看到的,我有一个底部栏(它没有使用TabHost或任何东西,部分原因是它显然贬值了,但部分原因是这只针对应用程序中的两个活动,所以我不需要只为两个页面做选项卡宿主)。无论如何,选项卡栏下面有内容。安卓不会再滚动了,因为在它看来,内容是可以查看的,但事实并非如此。

    我的问题是,什么是最好的方式来获取标签栏上方的内容。

    我有一些想法:

    1. 设置的高度(因为选项卡栏是设置的高度)和wrap_content的宽度的透明图像。这不起作用。
    2. 使用选项卡栏的背景,使其看起来不显眼。
    3. 使底部的酒吧不是透明的,并把任何东西放在那里,有一个设定的高度。

    您可能对我的xml结构感兴趣:

     <RelativeLayout>
       <ScrollView>
         <LinearLayout>
           <RelativeLayout>
             <LinearLayout>
    
             </LinearLayout>
    
             <LinearLayout>
    
             </LinearLayout>
           </RelativeLayout>
         </LinearLayout>
       </ScrollView>
       <LinearLayout>
         TAB BAR
       </LinearLayout>
     </RelativeLayout>
    

    screenshot

    4 回复  |  直到 13 年前
        1
  •  3
  •   Antarix    13 年前

    如果TAB栏的高度比您可以设置的高度固定 ScrollView margin-bottom属性。这将始终显示您 卷轴视图 选项卡栏上方的数据

        2
  •  0
  •   cjk    13 年前

    替代@Antarix Tandon的答案,您可以将根相对布局更改为垂直线性布局。

        3
  •  0
  •   laalto    13 年前

    RelativeLayout 除非另有规定,否则它会快乐地把所有的孩子放在一起。一些解决方法:

    • 更改顶部 相对布局 LinearLayout 具有 orientation="vertical" ScrollView layout_weight 指定为非零值,以便选项卡栏始终位于底部,滚动视图占据所有剩余的垂直空间。

    • 保留 相对布局 但首先使用布局选项卡栏 layout_alignParentBottom="true" 然后使用滚动视图 layout_above="@id/your_tabbar_id"

        4
  •  0
  •   biddulph.r    13 年前

    在xml中为选项卡栏指定一个视图id,然后将其后面的视图设置为选项卡栏视图的“layout_above”,并确保它们都在同一RelativeLayout内。

    因此,例如:

    <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
    
            <LinearLayout
                android:id="@+id/bottom_bar"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" />
    
           <LinearLayout
                android:id="@+id/top_area"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_above="@+id/bottom_bar"
                android:orientation="vertical" /> 
     </RelativeLayout>
    

    这将导致后面的内容被推到上面,然后您可以将top_area布局放入滚动视图中,然后滚动视图将是可滚动的,并且始终位于底部条的上方。

    例如:

    <ScrollView 
        android:id="@+id/scroller"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/bottom_bar" >
       <LinearLayout
            android:id="@+id/top_area"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" />
    </ScrollView>
    

    这将把滚动视图放在底部条的上方,其中包含top_area布局并可滚动