滚动型在TableLayout半屏其余按钮? [英] Scrollview in half screen rest Buttons in TableLayout?

查看:127
本文介绍了滚动型在TableLayout半屏其余按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

滚动型在TableLayout半屏其余按钮??

这是我的XML code..It给强制关闭的时候我加入了滚动视图否则它工作正常..
这是什么问题?

<?pre> &LT; XML版本=1.0编码=UTF-8&GT;&LT; LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk / RES / Android的
机器人:方向=垂直的android:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT&GT;&LT;景观的android:layout_width =FILL_PARENT机器人:layout_height =10dp&GT;&LT; /视图&gt;&LT;滚动型机器人:ID =@ + ID / ScrollView01
        机器人:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =0&GT;&LT; TableLayout的android:layout_width =FILL_PARENT
        机器人:layout_height =90dp机器人:背景=@绘制/ table_one&GT;
        &LT;的TableRow机器人:layout_height =20dp&GT;
            &LT;查看机器人:layout_height =20dp&GT;&LT; /视图&gt;
        &LT; /&的TableRow GT;
        &LT;的TableRow的android:layout_width =FILL_PARENT
            机器人:layout_height =40dp&GT;
            &LT; TextView的机器人:比重=中心|左机器人:文字颜色=#000000
                机器人:layout_height =40dp机器人:layout_weight =20
                机器人:文字=IP机器人:layout_marginLeft =4DP
                机器人:layout_width =70dp/&GT;            &LT; EditText上机器人:ID =@ + ID / remote_ip的android:layout_width =100dp
                机器人:layout_height =40dp机器人:layout_weight =80
                机器人:layout_marginRight =5DP&GT;&LT; /&的EditText GT;        &LT; /&的TableRow GT;
        &LT;的TableRow的android:layout_width =FILL_PARENT
            机器人:layout_height =40dp&GT;
        &LT; /&的TableRow GT;
        &LT;的TableRow的android:layout_width =FILL_PARENT
            机器人:layout_height =40dp&GT;        &LT; /&的TableRow GT;
    &LT; / TableLayout&GT;
    &LT;景观的android:layout_width =FILL_PARENT机器人:layout_height =10dp&GT;&LT; /视图&gt;
    &LT; TableLayout的android:layout_width =FILL_PARENT
        机器人:背景=@绘制/ table_two机器人:layout_height =90dp&GT;
        &LT;的TableRow机器人:layout_height =20dp&GT;
            &LT;查看机器人:layout_height =20dp&GT;&LT; /视图&gt;
        &LT; /&的TableRow GT;
        &LT;的TableRow的android:layout_width =FILL_PARENT
            机器人:layout_height =40dp&GT;
            &LT; TextView的机器人:比重=中心|左
                机器人:layout_width =70dp机器人:layout_height =40dp
                机器人:文字颜色=#000000机器人:文本=布局Orientantion
                机器人:layout_marginLeft =4DP机器人:layout_weight =40/&GT;            &LT;微调机器人:ID =@ + ID / spinner_layout机器人:比重=中心
                机器人:layout_width =180dp机器人:layout_height =40dp
                机器人:layout_marginRight =5DP机器人:layout_weight =60&GT;&LT; /微调&GT;        &LT; /&的TableRow GT;
    &LT; / TableLayout&GT;
    &LT;景观的android:layout_width =FILL_PARENT机器人:layout_height =10dp&GT;&LT; /视图&gt;
    &LT; TableLayout的android:layout_width =FILL_PARENT
        机器人:背景=@绘制/ table_two机器人:layout_height =120dp&GT;
        &LT;的TableRow机器人:layout_height =20dp&GT;
            &LT;查看机器人:layout_height =20dp&GT;&LT; /视图&gt;
        &LT; /&的TableRow GT;
        &LT;的TableRow的android:layout_width =FILL_PARENT
            机器人:layout_height =40dp&GT;
            &LT; TextView的机器人:比重=中心|左机器人:文字颜色=#000000
                机器人:layout_height =40dp机器人:layout_weight =20
                机器人:文字=用户名机器人:layout_marginLeft =4DP
                机器人:layout_width =70dp/&GT;            &LT; EditText上机器人:ID =@ + ID / remote_ip的android:layout_width =100dp
                机器人:layout_height =40dp机器人:layout_weight =80
                机器人:layout_marginRight =5DP&GT;&LT; /&的EditText GT;
        &LT; /&的TableRow GT;
        &LT;的TableRow的android:layout_width =FILL_PARENT
            机器人:layout_height =40dp&GT;
            &LT; TextView的机器人:比重=中心|左机器人:文字颜色=#000000
                机器人:layout_height =40dp机器人:layout_weight =20
                机器人:文字=密码机器人:layout_marginLeft =4DP
                机器人:layout_width =70dp/&GT;            &LT; EditText上机器人:ID =@ + ID / remote_ip的android:layout_width =100dp
                机器人:layout_height =40dp机器人:layout_weight =80
                机器人:密码=真正的机器人:layout_marginRight =5DP&GT;&LT; /&的EditText GT;
        &LT; /&的TableRow GT;
    &LT; / TableLayout&GT;
&LT; /滚动型&GT;
&LT;景观的android:layout_width =FILL_PARENT机器人:layout_height =10dp&GT;&LT; /视图&gt;
&LT; TableLayout机器人:方向=横向
    机器人:背景=@绘制/ my_bsckround的android:layout_width =FILL_PARENT
    机器人:重力=center_vertical机器人:layout_height =WRAP_CONTENT
    机器人:layout_weight =1&GT;
    &LT;&的TableRow GT;
        &LT;按钮的android:文本=保存机器人:ID =@ + ID / btn_save_settings
            机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =50&GT;&LT; /按钮&GT;        &LT;按钮的android:文本=取消机器人:ID =@ + ID / btn_setng_cncl
            机器人:layout_width =WRAP_CONTENT机器人:layout_weight =50
            机器人:layout_height =WRAP_CONTENT&GT;&LT; /按钮&GT;
    &LT; /&的TableRow GT;
&LT; / TableLayout&GT;
&LT;景观的android:layout_width =FILL_PARENT机器人:layout_height =10dp&GT;&LT; /视图&gt;


解决方案

它由于滚动型的发生只能有一个直接子。所以,把你所有的表格布局为一个线性布局如下图所示。

 &LT;?XML版本=1.0编码=UTF-8&GT?;
&LT; LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直的android:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT&GT;
    &LT;景观的android:layout_width =FILL_PARENT机器人:layout_height =10dp&GT;&LT; /视图&gt;
    &LT;滚动型机器人:ID =@ + ID / ScrollView01
        机器人:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =0&GT;
        &LT;的LinearLayout机器人:方向=垂直
            机器人:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT&GT;
            &LT; TableLayout的android:layout_width =FILL_PARENT
                机器人:layout_height =90dp机器人:背景=@绘制/ table_one&GT;
                &LT;的TableRow机器人:layout_height =20dp&GT;
                    &LT;查看机器人:layout_height =20dp&GT;&LT; /视图&gt;
                &LT; /&的TableRow GT;
                &LT;的TableRow的android:layout_width =FILL_PARENT
                    机器人:layout_height =40dp&GT;
                    &LT; TextView的机器人:比重=中心|左机器人:文字颜色=#000000
                        机器人:layout_height =40dp机器人:layout_weight =20
                        机器人:文字=IP机器人:layout_marginLeft =4DP
                        机器人:layout_width =70dp/&GT;
                    &LT; EditText上机器人:ID =@ + ID / remote_ip
                        机器人:layout_width =100dp机器人:layout_height =40dp
                        机器人:layout_weight =80机器人:layout_marginRight =5DP&GT;&LT; /&的EditText GT;
                &LT; /&的TableRow GT;
                &LT;的TableRow的android:layout_width =FILL_PARENT
                    机器人:layout_height =40dp&GT;
                &LT; /&的TableRow GT;
                &LT;的TableRow的android:layout_width =FILL_PARENT
                    机器人:layout_height =40dp&GT;
                &LT; /&的TableRow GT;
            &LT; / TableLayout&GT;
            &LT;景观的android:layout_width =FILL_PARENT机器人:layout_height =10dp&GT;&LT; /视图&gt;
            &LT; TableLayout的android:layout_width =FILL_PARENT
                机器人:背景=@绘制/ table_two机器人:layout_height =90dp&GT;
                &LT;的TableRow机器人:layout_height =20dp&GT;
                    &LT;查看机器人:layout_height =20dp&GT;&LT; /视图&gt;
                &LT; /&的TableRow GT;
                &LT;的TableRow的android:layout_width =FILL_PARENT
                    机器人:layout_height =40dp&GT;
                    &LT; TextView的机器人:比重=中心|左
                        机器人:layout_width =70dp机器人:layout_height =40dp
                        机器人:文字颜色=#000000机器人:文本=布局Orientantion
                        机器人:layout_marginLeft =4DP机器人:layout_weight =40/&GT;
                    &LT;微调机器人:ID =@ + ID / spinner_layout机器人:比重=中心
                        机器人:layout_width =180dp机器人:layout_height =40dp
                        机器人:layout_marginRight =5DP机器人:layout_weight =60&GT;&LT; /微调&GT;
                &LT; /&的TableRow GT;
            &LT; / TableLayout&GT;
            &LT;景观的android:layout_width =FILL_PARENT机器人:layout_height =10dp&GT;&LT; /视图&gt;
            &LT; TableLayout的android:layout_width =FILL_PARENT
                机器人:背景=@绘制/ table_two机器人:layout_height =120dp&GT;
                &LT;的TableRow机器人:layout_height =20dp&GT;
                    &LT;查看机器人:layout_height =20dp&GT;&LT; /视图&gt;
                &LT; /&的TableRow GT;
                &LT;的TableRow的android:layout_width =FILL_PARENT
                    机器人:layout_height =40dp&GT;
                    &LT; TextView的机器人:比重=中心|左机器人:文字颜色=#000000
                        机器人:layout_height =40dp机器人:layout_weight =20
                        机器人:文字=用户名机器人:layout_marginLeft =4DP
                        机器人:layout_width =70dp/&GT;
                    &LT; EditText上机器人:ID =@ + ID / remote_ip
                        机器人:layout_width =100dp机器人:layout_height =40dp
                        机器人:layout_weight =80机器人:layout_marginRight =5DP&GT;&LT; /&的EditText GT;
                &LT; /&的TableRow GT;
                &LT;的TableRow的android:layout_width =FILL_PARENT
                    机器人:layout_height =40dp&GT;
                    &LT; TextView的机器人:比重=中心|左机器人:文字颜色=#000000
                        机器人:layout_height =40dp机器人:layout_weight =20
                        机器人:文字=密码机器人:layout_marginLeft =4DP
                        机器人:layout_width =70dp/&GT;
                    &LT; EditText上机器人:ID =@ + ID / remote_ip
                        机器人:layout_width =100dp机器人:layout_height =40dp
                        机器人:layout_weight =80机器人:密码=真
                        机器人:layout_marginRight =5DP&GT;&LT; /&的EditText GT;
                &LT; /&的TableRow GT;
            &LT; / TableLayout&GT;
        &LT; / LinearLayout中&GT;
    &LT; /滚动型&GT;
    &LT;景观的android:layout_width =FILL_PARENT机器人:layout_height =10dp&GT;&LT; /视图&gt;
    &LT; TableLayout机器人:方向=横向
        机器人:背景=@绘制/ my_bsckround的android:layout_width =FILL_PARENT
        机器人:重力=center_vertical机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1&GT;
        &LT;&的TableRow GT;
            &LT;按钮的android:文本=保存机器人:ID =@ + ID / btn_save_settings
                机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT
                机器人:layout_weight =50&GT;&LT; /按钮&GT;
            &LT;按钮的android:文本=取消机器人:ID =@ + ID / btn_setng_cncl
                机器人:layout_width =WRAP_CONTENT机器人:layout_weight =50
                机器人:layout_height =WRAP_CONTENT&GT;&LT; /按钮&GT;
        &LT; /&的TableRow GT;
    &LT; / TableLayout&GT;
    &LT;景观的android:layout_width =FILL_PARENT机器人:layout_height =10dp&GT;&LT; /视图&gt;
&LT; / LinearLayout中&GT;

Scrollview in half screen rest Buttons in TableLayout??

This is my Xml Code..It gives force close when i added the scrollView otherwise it was working fine.. What is the Problem?

<?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"><View android:layout_width="fill_parent" android:layout_height="10dp"></View><ScrollView android:id="@+id/ScrollView01"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_weight="0"><TableLayout android:layout_width="fill_parent"
        android:layout_height="90dp" android:background="@drawable/table_one">
        <TableRow android:layout_height="20dp">
            <View android:layout_height="20dp"></View>
        </TableRow>
        <TableRow android:layout_width="fill_parent"
            android:layout_height="40dp">
            <TextView android:gravity="center|left" android:textColor="#000000"
                android:layout_height="40dp" android:layout_weight="20"
                android:text="IP" android:layout_marginLeft="4dp"
                android:layout_width="70dp" />

            <EditText android:id="@+id/remote_ip" android:layout_width="100dp"
                android:layout_height="40dp" android:layout_weight="80"
                android:layout_marginRight="5dp"></EditText>

        </TableRow>
        <TableRow android:layout_width="fill_parent"
            android:layout_height="40dp">


        </TableRow>
        <TableRow android:layout_width="fill_parent"
            android:layout_height="40dp">

        </TableRow>
    </TableLayout>
    <View android:layout_width="fill_parent" android:layout_height="10dp"></View>
    <TableLayout android:layout_width="fill_parent"
        android:background="@drawable/table_two" android:layout_height="90dp">
        <TableRow android:layout_height="20dp">
            <View android:layout_height="20dp"></View>
        </TableRow>
        <TableRow android:layout_width="fill_parent"
            android:layout_height="40dp">
            <TextView android:gravity="center|left"
                android:layout_width="70dp" android:layout_height="40dp"
                android:textColor="#000000" android:text="Layout Orientantion"
                android:layout_marginLeft="4dp" android:layout_weight="40" />

            <Spinner android:id="@+id/spinner_layout" android:gravity="center"
                android:layout_width="180dp" android:layout_height="40dp"
                android:layout_marginRight="5dp" android:layout_weight="60"></Spinner>

        </TableRow>
    </TableLayout>
    <View android:layout_width="fill_parent" android:layout_height="10dp"></View>
    <TableLayout android:layout_width="fill_parent"
        android:background="@drawable/table_two" android:layout_height="120dp">
        <TableRow android:layout_height="20dp">
            <View android:layout_height="20dp"></View>
        </TableRow>
        <TableRow android:layout_width="fill_parent"
            android:layout_height="40dp">
            <TextView android:gravity="center|left" android:textColor="#000000"
                android:layout_height="40dp" android:layout_weight="20"
                android:text="User Name" android:layout_marginLeft="4dp"
                android:layout_width="70dp" />

            <EditText android:id="@+id/remote_ip" android:layout_width="100dp"
                android:layout_height="40dp" android:layout_weight="80"
                android:layout_marginRight="5dp"></EditText>
        </TableRow>
        <TableRow android:layout_width="fill_parent"
            android:layout_height="40dp">
            <TextView android:gravity="center|left" android:textColor="#000000"
                android:layout_height="40dp" android:layout_weight="20"
                android:text="Password" android:layout_marginLeft="4dp"
                android:layout_width="70dp" />

            <EditText android:id="@+id/remote_ip" android:layout_width="100dp"
                android:layout_height="40dp" android:layout_weight="80"
                android:password="true" android:layout_marginRight="5dp"></EditText>
        </TableRow>
    </TableLayout>
</ScrollView>
<View android:layout_width="fill_parent" android:layout_height="10dp"></View>
<TableLayout android:orientation="horizontal"
    android:background="@drawable/my_bsckround" android:layout_width="fill_parent"
    android:gravity="center_vertical" android:layout_height="wrap_content"
    android:layout_weight="1">
    <TableRow>
        <Button android:text="Save" android:id="@+id/btn_save_settings"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:layout_weight="50"></Button>

        <Button android:text="Cancel" android:id="@+id/btn_setng_cncl"
            android:layout_width="wrap_content" android:layout_weight="50"
            android:layout_height="wrap_content"></Button>
    </TableRow>
</TableLayout>
<View android:layout_width="fill_parent" android:layout_height="10dp"></View>

解决方案

Its happening because of the ScrollView can have only one direct child. So put your all table layouts into one linear layout like below.

<?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">
    <View android:layout_width="fill_parent" android:layout_height="10dp"></View>
    <ScrollView android:id="@+id/ScrollView01"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_weight="0">
        <LinearLayout android:orientation="vertical"
            android:layout_width="fill_parent" android:layout_height="wrap_content">
            <TableLayout android:layout_width="fill_parent"
                android:layout_height="90dp" android:background="@drawable/table_one">
                <TableRow android:layout_height="20dp">
                    <View android:layout_height="20dp"></View>
                </TableRow>
                <TableRow android:layout_width="fill_parent"
                    android:layout_height="40dp">
                    <TextView android:gravity="center|left" android:textColor="#000000"
                        android:layout_height="40dp" android:layout_weight="20"
                        android:text="IP" android:layout_marginLeft="4dp"
                        android:layout_width="70dp" />
                    <EditText android:id="@+id/remote_ip"
                        android:layout_width="100dp" android:layout_height="40dp"
                        android:layout_weight="80" android:layout_marginRight="5dp"></EditText>
                </TableRow>
                <TableRow android:layout_width="fill_parent"
                    android:layout_height="40dp">
                </TableRow>
                <TableRow android:layout_width="fill_parent"
                    android:layout_height="40dp">
                </TableRow>
            </TableLayout>
            <View android:layout_width="fill_parent" android:layout_height="10dp"></View>
            <TableLayout android:layout_width="fill_parent"
                android:background="@drawable/table_two" android:layout_height="90dp">
                <TableRow android:layout_height="20dp">
                    <View android:layout_height="20dp"></View>
                </TableRow>
                <TableRow android:layout_width="fill_parent"
                    android:layout_height="40dp">
                    <TextView android:gravity="center|left"
                        android:layout_width="70dp" android:layout_height="40dp"
                        android:textColor="#000000" android:text="Layout Orientantion"
                        android:layout_marginLeft="4dp" android:layout_weight="40" />
                    <Spinner android:id="@+id/spinner_layout" android:gravity="center"
                        android:layout_width="180dp" android:layout_height="40dp"
                        android:layout_marginRight="5dp" android:layout_weight="60"></Spinner>
                </TableRow>
            </TableLayout>
            <View android:layout_width="fill_parent" android:layout_height="10dp"></View>
            <TableLayout android:layout_width="fill_parent"
                android:background="@drawable/table_two" android:layout_height="120dp">
                <TableRow android:layout_height="20dp">
                    <View android:layout_height="20dp"></View>
                </TableRow>
                <TableRow android:layout_width="fill_parent"
                    android:layout_height="40dp">
                    <TextView android:gravity="center|left" android:textColor="#000000"
                        android:layout_height="40dp" android:layout_weight="20"
                        android:text="User Name" android:layout_marginLeft="4dp"
                        android:layout_width="70dp" />
                    <EditText android:id="@+id/remote_ip"
                        android:layout_width="100dp" android:layout_height="40dp"
                        android:layout_weight="80" android:layout_marginRight="5dp"></EditText>
                </TableRow>
                <TableRow android:layout_width="fill_parent"
                    android:layout_height="40dp">
                    <TextView android:gravity="center|left" android:textColor="#000000"
                        android:layout_height="40dp" android:layout_weight="20"
                        android:text="Password" android:layout_marginLeft="4dp"
                        android:layout_width="70dp" />
                    <EditText android:id="@+id/remote_ip"
                        android:layout_width="100dp" android:layout_height="40dp"
                        android:layout_weight="80" android:password="true"
                        android:layout_marginRight="5dp"></EditText>
                </TableRow>
            </TableLayout>
        </LinearLayout>
    </ScrollView>
    <View android:layout_width="fill_parent" android:layout_height="10dp"></View>
    <TableLayout android:orientation="horizontal"
        android:background="@drawable/my_bsckround" android:layout_width="fill_parent"
        android:gravity="center_vertical" android:layout_height="wrap_content"
        android:layout_weight="1">
        <TableRow>
            <Button android:text="Save" android:id="@+id/btn_save_settings"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:layout_weight="50"></Button>
            <Button android:text="Cancel" android:id="@+id/btn_setng_cncl"
                android:layout_width="wrap_content" android:layout_weight="50"
                android:layout_height="wrap_content"></Button>
        </TableRow>
    </TableLayout>
    <View android:layout_width="fill_parent" android:layout_height="10dp"></View>
</LinearLayout>

这篇关于滚动型在TableLayout半屏其余按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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