RelativeLayout的滚动 [英] RelativeLayout Scrollable

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

问题描述

我已经试过多次aligh我RelativeLayout的元素,但我不明白的结果,我希望是:

我想调整的第一个按钮顶部右侧,然后我有多个TextView的,我希望所有的人都滚动的,但是当我插入标签我得到一个错误,这是我的code:

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:ID =@ + ID / RL01
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =FILL_PARENT
  机器人:方向=垂直
  机器人:填充=5DP>

     <滚动型
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT>

    <按钮
          机器人:ID =@ + ID / btnBrowser
          机器人:layout_width =WRAP_CONTENT
          机器人:layout_height =WRAP_CONTENT
          机器人:文本=浏览器
          机器人:layout_marginTop =5DP
            >
    < /按钮>

        <的TextView
        机器人:ID =@ + ID / txtAuthor
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:TEXTSIZE =20dp
        机器人:TEXTSTYLE =黑体
        机器人:文字颜色=#143781
        机器人:layout_marginTop =10dp
        机器人:layout_marginLeft =20dp
        机器人:layout_below =@ + ID / btnBrowser
        >
    < / TextView的>
    <的TextView
        机器人:ID =@ + ID / txtDate
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:TEXTSIZE =14dp
        机器人:文字颜色=#8D89B3
        机器人:layout_marginTop =5DP
        机器人:layout_marginLeft =20dp
        机器人:layout_below =@ + ID / txtAuthor>
    < / TextView的>
    <的TextView
        机器人:ID =@ + ID / txtTitle
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:TEXTSIZE =14dp
        机器人:TEXTSTYLE =黑体
        机器人:文字颜色=#000000
        机器人:layout_marginLeft =20dp
        机器人:layout_marginTop =5DP
        机器人:layout_below =@ + ID / txtDate>
        >
    < / TextView的>
    <的TextView
        机器人:ID =@ + ID / txtMsg
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_width =WRAP_CONTENT
        机器人:TEXTSIZE =14dp
        机器人:文字颜色=#000000
        机器人:layout_marginLeft =20dp
        机器人:layout_below =@ + ID / txtTitle>
    < / TextView的>

    <按钮
          机器人:ID =@ + ID / btnReply
          机器人:layout_width =WRAP_CONTENT
          机器人:layout_height =WRAP_CONTENT
          机器人:文本=回复
          机器人:layout_marginTop =20dp
          机器人:layout_below =@ + ID / txtMsg
          机器人:layout_centerInParent =@ + ID / txtMsg>

    < /按钮>
       < /滚动型>
< / RelativeLayout的>
 

解决方案

滚动型剂量不允许超过一个直接的孩子,这就是为什么你得到错误。所以,你试试如下:

 <滚动型的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT>

< RelativeLayout的
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =FILL_PARENT>
         <按钮
        机器人:ID =@ + ID /按钮1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentRight =真
        机器人:layout_alignParentTop =真
        机器人:文本=按钮/>

    <的TextView
        机器人:ID =@ + ID / textView1
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_below =@ + ID /按钮1
        机器人:文本=TextView的/>

    <的TextView
        机器人:ID =@ + ID / textView2
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_below =@ + ID / textView1
        机器人:文本=TextView的/>

    <的TextView
        机器人:ID =@ + ID / textView3
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_below =@ + ID / textView2
        机器人:文本=TextView的/>

    <按钮
        机器人:ID =@ + ID /按钮2
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentBottom =真
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_below =@ + ID / textView3
        机器人:文本=按钮/>

     < / RelativeLayout的>
< /滚动型>
 

I have tried many times to aligh the elements in my RelativeLayout but I dont get the result I expected that is:

I'd like to align the first button to top right and then I have multiple Textview and I want all of them Scrollable, but when I insert the tag I get an error, this is my code:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/RL01"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:padding="5dp">

     <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    <Button
          android:id="@+id/btnBrowser"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Browser"
          android:layout_marginTop="5dp"
            >
    </Button>

        <TextView
        android:id="@+id/txtAuthor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:textStyle="bold"
        android:textColor="#143781"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="20dp"
        android:layout_below="@+id/btnBrowser"
        >
    </TextView>
    <TextView
        android:id="@+id/txtDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="14dp"
        android:textColor="#8D89B3"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="20dp"
        android:layout_below="@+id/txtAuthor">
    </TextView>
    <TextView
        android:id="@+id/txtTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="14dp"
        android:textStyle="bold"
        android:textColor="#000000"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="5dp"
        android:layout_below="@+id/txtDate">
        >
    </TextView>
    <TextView
        android:id="@+id/txtMsg"
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        android:textSize="14dp"
        android:textColor="#000000"
        android:layout_marginLeft="20dp"
        android:layout_below="@+id/txtTitle">
    </TextView>

    <Button
          android:id="@+id/btnReply"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Reply"
          android:layout_marginTop="20dp"
          android:layout_below="@+id/txtMsg"
          android:layout_centerInParent="@+id/txtMsg">

    </Button>
       </ScrollView>
</RelativeLayout>

解决方案

ScrollView dose not allow more than one direct child, thats why you getting error. So you try as follows

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
        android:layout_height="fill_parent">

<RelativeLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
         <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="Button" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/button1"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView2"
        android:text="TextView" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/textView3"
        android:text="Button" />

     </RelativeLayout>
</ScrollView>

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

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