滚动型仅在Android的屏幕部分 [英] ScrollView only on part of the screen in Android

查看:110
本文介绍了滚动型仅在Android的屏幕部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个部分的屏幕。我想最上面的一个是静态的和下一个具有TableLayout是滚动的。我已经尝试添加一个滚动型到屏幕的下部,但使得TableLayout时SCROLLABLE顶端部消失。

我如何用滚动下部结合顶部静态部分?

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:ID =@ + ID / LinearLayout01
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=横向
    机器人:layout_weight =9
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:背景=@绘制/ title_shape>
    <按钮
        机器人:ID =@ + ID / btnBack
        机器人:文字=@字符串/ titleCreateTest
        风格=@风格/ Bar_buttonBack>
    < /按钮>
    < TextView的机器人:layout_weight =6
        机器人:ID =@ + ID / titleFlashcard
        机器人:文字=@字符串/ titleStatistic
        风格=@风格/ TitleStyle>
    < / TextView的>
< / LinearLayout中>
 <滚动型
  机器人:ID =@ + ID / ScrollView1
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT>
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:ID =@ + ID / LinearLayout2
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT>
< TableLayout
    机器人:ID =@ + ID / table_layout
    风格=@风格/ TableLayoutStyle>
 <的TableRow
     机器人:ID =@ + ID / table_row1>
    <的TextView
            机器人:ID =@ + ID / TV1
            机器人:文字=@字符串/ tvRecord
            风格=@风格/ TableRowStyle/>
    <的TextView
            机器人:ID =@ + ID / tv1v
            风格=@风格/ TableRowStyleColumn2/>
  < /&的TableRow GT;
  <查看
    风格=@风格/ TableRowSeparator/>
     <的TableRow
     机器人:ID =@ + ID / table_row2>
        <的TextView
            机器人:ID =@ + ID / TV2
            机器人:文字=@字符串/ tvMedium
            风格=@风格/ TableRowStyle/>
        <的TextView
            机器人:ID =@ + ID / tv2v
            风格=@风格/ TableRowStyleColumn2/>
    < /&的TableRow GT;
      <查看
    风格=@风格/ TableRowSeparator/>
    <的TableRow
    机器人:ID =@ + ID / table_row3>
        <的TextView
            机器人:ID =@ + ID / TV3
            机器人:文字=@字符串/ tvWorst
            风格=@风格/ TableRowStyle/>
        <的TextView
            机器人:ID =@ + ID / tv3v
            风格=@风格/ TableRowStyleColumn2/>
    < /&的TableRow GT;
    < / TableLayout>
   < TableLayout
    机器人:ID =@ + ID / table_layout2
    风格=@风格/ TableLayoutStyle>
        <的TableRow
          机器人:ID =@ + ID / table_row4>
          <的TextView
            机器人:ID =@ + ID / tvDate
            风格=@风格/ TableRowStyle/>
            <的TextView
            机器人:ID =@ + ID / tvResult
            风格=@风格/ TableRowStyleColumn2/>
     < /&的TableRow GT;
    <查看
    机器人:ID =@ + ID / rowseparator
    风格=@风格/ TableRowSeparator/>
< / TableLayout>
< / LinearLayout中>
< /滚动型>
< / LinearLayout中>


解决方案

同时使用 FILL_PARENT 机器人:体重可能会非常棘手。有一个关于它的讨论,但我找不到它。

被设置为 FILL_PARENT 你的第二个线性布局(带有按钮的TextView),我希望它的根布局吃了所有的空间,但随着重量设置似乎表现得像一个逆权重,并让滚动型把所有的空间。

这将是更好地给上部的高度WRAP_CONTENT和FILL_PARENT到滚动型。如果preFER,可以设置顶端部的高度= WRAP_CONTENT和重量= 0,和底部的高度= 0和重= 1,因此,它需要留下的所有空间。

如果您设置了滚动型 WRAP_CONTENT ,这将是宽(或高)不亚于其内容。难道滚动或刚结束了在屏幕外?

的LinearLayout 中的滚动型是没用的,除非你打算添加别的东西。

最后一点:在的xmlns:安卓=...应该留只在根元素

Android的布局框架是知道有时是一个挑战,我希望这有助于。

I have a screen with two parts. I want the top one to be static and the lower one with a TableLayout to be scrollable. I have tried adding a ScrollView to the lower part of the screen, but when making the TableLayout scrollable the top part disappears.

How can I combine the top static part with a scrollable lower part?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_weight="9" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/title_shape">  
    <Button 
        android:id="@+id/btnBack" 
        android:text="@string/titleCreateTest"
        style="@style/Bar_buttonBack">
    </Button>
    <TextView android:layout_weight="6" 
        android:id="@+id/titleFlashcard" 
        android:text="@string/titleStatistic" 
        style="@style/TitleStyle">
    </TextView> 
</LinearLayout>
 <ScrollView
  android:id="@+id/ScrollView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:id="@+id/LinearLayout2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
<TableLayout 
    android:id="@+id/table_layout"
    style="@style/TableLayoutStyle">
 <TableRow 
     android:id="@+id/table_row1">
    <TextView
            android:id="@+id/tv1"
            android:text="@string/tvRecord" 
            style="@style/TableRowStyle"/>
    <TextView
            android:id="@+id/tv1v"
            style="@style/TableRowStyleColumn2"/>
  </TableRow>
  <View
    style="@style/TableRowSeparator"/>
     <TableRow
     android:id="@+id/table_row2">
        <TextView
            android:id="@+id/tv2"
            android:text="@string/tvMedium" 
            style="@style/TableRowStyle"/>
        <TextView
            android:id="@+id/tv2v"
            style="@style/TableRowStyleColumn2"/>
    </TableRow>
      <View
    style="@style/TableRowSeparator"/>
    <TableRow
    android:id="@+id/table_row3">
        <TextView
            android:id="@+id/tv3"
            android:text="@string/tvWorst" 
            style="@style/TableRowStyle"/>
        <TextView
            android:id="@+id/tv3v"
            style="@style/TableRowStyleColumn2"/>
    </TableRow>
    </TableLayout> 
   <TableLayout 
    android:id="@+id/table_layout2"
    style="@style/TableLayoutStyle">
        <TableRow
          android:id="@+id/table_row4">
          <TextView
            android:id="@+id/tvDate"
            style="@style/TableRowStyle"/>
            <TextView
            android:id="@+id/tvResult"
            style="@style/TableRowStyleColumn2"/>
     </TableRow>
    <View
    android:id="@+id/rowseparator"
    style="@style/TableRowSeparator"/>
</TableLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>

解决方案

Using both fill_parent and android:weight can be tricky. There was a discussion about it but I can't find it.

Being your second linear layout (the one with button and textview) set to fill_parent, I would expect it to eat up all the space in the root layout, but with a weight set it seems to behave like an "inverse weight" and lets the ScrollView take all the space.

It would be better to give the top part a wrap_content in height, and a fill_parent to the ScrollView. If you prefer, you could set top part's height=wrap_content and weight=0, and the bottom part's height=0 and weight=1 so that it takes all the space left.

If you set a ScrollView to wrap_content, it will be wide (or tall) as much as its content. Is it scrolling or just ending up outside the screen?

The LinearLayout inside the ScrollView is useless, unless you're planning to add something else.

One last note: the xmlns:android="...." should stay only in the root element.

Android layout framework is know for being a challenge sometimes, I hope this helped.

这篇关于滚动型仅在Android的屏幕部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆