滚动型问题在Android的布局XML [英] Scrollview issue in Android layout xml

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

问题描述

我想设置在屏幕中间的滚动视图,在报头(tablelayout)和页脚(在ralativelayout按钮)之间....我的问题是,虽然子项(的EditText和微调)留在被分配的区域,滚动条延伸在屏幕的整个长度。知不知道我做错了吗?先谢谢了。

下面是XML:

 < XML版本=1.0编码=UTF-8&GT?;

< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>

    < TableLayout机器人:ID =@ + ID / TableLayout01机器人:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT机器人:stretchColumns =0>

  <的TableRow机器人:ID =@ + ID / TableRow01机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>

        < TextView的Andr​​oid的:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文本=@字符串/标题/>
        < EditText上机器人:ID =@ + ID /标题
          机器人:layout_height =WRAP_CONTENT
            机器人:layout_width =WRAP_CONTENT机器人:提示=蒙太圣/>
  < /的TableRow>

  <的TableRow机器人:ID =@ + ID / TableRow02机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>

        < TextView的Andr​​oid的:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文本=@串/体/>
        < EditText上机器人:ID =@ + ID /体机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =1
            机器人:滚动条=垂直机器人:提示=44/>
        < /的TableRow>


    < / TableLayout><的TableRow机器人:ID =@ + ID / TableRow03机器人:layout_height =WRAP_CONTENT机器人:layout_width =WRAP_CONTENT>< TextView的机器人:ID =@ + ID / TextView01机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文本=门牌号码>< / TextView的>
< TextView的机器人:ID =@ + ID / TextView02机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文本=状态>< / TextView的>
< TextView的机器人:ID =@ + ID / TextView03机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文本=#的访问>< / TextView的>
< /的TableRow>

<滚动型机器人:ID =@ + ID / ScrollView01机器人:isScrollContainer =真正的机器人:layout_width =WRAP_CONTENT机器人:clipChildren =真正的机器人:clipToPadding =真正的机器人:layout_height =WRAP_CONTENT机器人:layout_marginBottom =50dip>


<的LinearLayout机器人:ID =@ + ID / LinearLayout01机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:方向=垂直>< TableLayout机器人:ID =@ + ID / TableLayout02 机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>



<的TableRow机器人:ID =@ + ID / TableRow04机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< EditText上机器人:ID =@ + ID / EditText01机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT机器人:提示=门牌号码>< /的EditText>
<微调机器人:ID =@ + ID / Spinner01机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
<微调机器人:ID =@ + ID / Spinner02机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
< /的TableRow>
<的TableRow机器人:ID =@ + ID / TableRow04机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< EditText上机器人:ID =@ + ID / EditText01机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT>< /的EditText>
<微调机器人:ID =@ + ID / Spinner01机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
<微调机器人:ID =@ + ID / Spinner02机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
< /的TableRow>
<的TableRow机器人:ID =@ + ID / TableRow04机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< EditText上机器人:ID =@ + ID / EditText01机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT>< /的EditText>
<微调机器人:ID =@ + ID / Spinner01机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
<微调机器人:ID =@ + ID / Spinner02机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
< /的TableRow>
<的TableRow机器人:ID =@ + ID / TableRow04机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< EditText上机器人:ID =@ + ID / EditText01机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT>< /的EditText>
<微调机器人:ID =@ + ID / Spinner01机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
<微调机器人:ID =@ + ID / Spinner02机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
< /的TableRow>
<的TableRow机器人:ID =@ + ID / TableRow04机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< EditText上机器人:ID =@ + ID / EditText01机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT>< /的EditText>
<微调机器人:ID =@ + ID / Spinner01机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
<微调机器人:ID =@ + ID / Spinner02机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
< /的TableRow>
<的TableRow机器人:ID =@ + ID / TableRow04机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< EditText上机器人:ID =@ + ID / EditText01机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT>< /的EditText>
<微调机器人:ID =@ + ID / Spinner01机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
<微调机器人:ID =@ + ID / Spinner02机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
< /的TableRow>
<的TableRow机器人:ID =@ + ID / TableRow04机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< EditText上机器人:ID =@ + ID / EditText01机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT>< /的EditText>
<微调机器人:ID =@ + ID / Spinner01机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
<微调机器人:ID =@ + ID / Spinner02机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
< /的TableRow>
<的TableRow机器人:ID =@ + ID / TableRow04机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< EditText上机器人:ID =@ + ID / EditText01机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT>< /的EditText>
<微调机器人:ID =@ + ID / Spinner01机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
<微调机器人:ID =@ + ID / Spinner02机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< /微调>
< /的TableRow>
< / TableLayout>
< / LinearLayout中>
< /滚动型>
< RelativeLayout的机器人:layout_marginTop = -  50dip安卓重力=自下而上的Andr​​oid版本:layout_height =WRAP_CONTENT机器人:layout_width =FILL_PARENT>
<按钮机器人:ID =@ + ID /确认
      机器人:文本=@字符串/确认
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT/> < / RelativeLayout的>

< / LinearLayout中>
 

解决方案

您应该看一看到Android:layout_weight属性

I am trying to set up a scrollview in the middle of the screen, in between a header (tablelayout) and a footer (button within ralativelayout).... My problem is that while the child items (edittext and spinners) stay in the assigned area, the scrollbar extends the entire length of the screen. Any idea what I'm doing wrong? Thanks in advance.

Here is the xml:

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

    <TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content"  android:stretchColumns="0">

  <TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content">

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:text="@string/title" />
        <EditText android:id="@+id/title" 
          android:layout_height="wrap_content" 
            android:layout_width="wrap_content" android:hint="Montague St."/>
  </TableRow>

  <TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content">

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="@string/body" />
        <EditText android:id="@+id/body" android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:scrollbars="vertical" android:hint="44"/>
        </TableRow>


    </TableLayout><TableRow android:id="@+id/TableRow03" android:layout_height="wrap_content" android:layout_width="wrap_content"><TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="House Number                 "></TextView>
<TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Status         "></TextView>
<TextView android:id="@+id/TextView03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="# of Visits"></TextView>
</TableRow>

<ScrollView android:id="@+id/ScrollView01" android:isScrollContainer="true" android:layout_width="wrap_content" android:clipChildren="true" android:clipToPadding="true" android:layout_height="wrap_content" android:layout_marginBottom="50dip">


<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"><TableLayout android:id="@+id/TableLayout02" android:layout_width="wrap_content" android:layout_height="wrap_content">



<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="House Number   "></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content"><EditText android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Spinner>
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout android:layout_marginTop="-50dip" android:gravity="bottom" android:layout_height="wrap_content" android:layout_width="fill_parent">
<Button android:id="@+id/confirm" 
      android:text="@string/confirm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>     </RelativeLayout>    

</LinearLayout>

解决方案

You should take a look to android:layout_weight attribute

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

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