滚动型中相对布局 [英] Relative Layout in ScrollView

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

问题描述

我有多个ImageView的当我转身的屏幕上,imageviews变得紊乱......所以我决定把它包装成一个滚动视图...但滚动视图相对布局不起作用! !任何一个可以帮助我吗?我知道,正确的方法是设计一个GridView或ListView ......但因为我有一些问题,并在stackoverfloa没有人回答我,我决定走这条路。 这里是我的XML code:

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


<滚动型的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / ScrollView01
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:fillViewport =真
    机器人:滚动条=无>


< RelativeLayout的
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>


    <按钮
        机器人:ID =@ + ID / continuePizza
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentBottom =真
        机器人:layout_alignParentRight =真
        机器人:文本=继续/>

    <按钮
        机器人:ID =@ + ID / finishP
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_above =@ + ID / continuePizza
        机器人:layout_alignParentLeft =真
        机器人:文本=完成/>

    < ImageView的
        机器人:ID =@ + ID / imageView1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentTop =真
        机器人:layout_marginTop =16DP
        机器人:SRC =@可绘制/下载/>

    < ImageView的
        机器人:ID =@ + ID / imageView2
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignTop =@ + ID / imageView1
        机器人:layout_marginLeft =18dp
        机器人:layout_toRightOf =@ + ID / imageView1
        机器人:SRC =@可绘制/下载/>

    < ImageView的
        机器人:ID =@ + ID / imageView3
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_below =@ + ID / imageView1
        机器人:layout_marginTop =18dp
        机器人:SRC =@可绘制/下载/>

    < ImageView的
        机器人:ID =@ + ID / imageView5
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignLeft =@ + ID / imageView3
        机器人:layout_centerVertical =真
        机器人:SRC =@可绘制/下载/>

    < ImageView的
        机器人:ID =@ + ID / imageView6
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignTop =@ + ID / imageView3
        机器人:SRC =@可绘制/下载/>

    < ImageView的
        机器人:ID =@ + ID / imageView4
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_below =@ + ID / imageView5
        机器人:layout_marginTop =17dp
        机器人:SRC =@可绘制/下载/>

    < ImageView的
        机器人:ID =@ + ID / imageView7
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignLeft =@ + ID / imageView2
        机器人:layout_alignTop =@ + ID / imageView5
        机器人:layout_marginLeft =10dp
        机器人:SRC =@可绘制/下载/>
    < ImageView的
        机器人:ID =@ + ID / imageView8
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignLeft =@ + ID / imageView7
        机器人:layout_alignTop =@ + ID / imageView3
        机器人:SRC =@可绘制/下载/>

< / RelativeLayout的>

< /滚动型>
 

解决方案

我经历了同样的问题,在滚动视图相对布局来克服这个我缠在我与线性布局相对布局,尝试像这样,也从相对取出方向布局

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


<滚动型的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:ID =@ + ID / ScrollView01
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fillViewport =真
机器人:滚动条=无>

< LinearLayout中的android:layout_width =match_parent
机器人:layout_height =match_parent>


< RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =match_parent
>


<按钮
    机器人:ID =@ + ID / continuePizza
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真
    机器人:layout_alignParentRight =真
    机器人:文本=继续/>

<按钮
    机器人:ID =@ + ID / finishP
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_above =@ + ID / continuePizza
    机器人:layout_alignParentLeft =真
    机器人:文本=完成/>

< ImageView的
    机器人:ID =@ + ID / imageView1
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentLeft =真
    机器人:layout_alignParentTop =真
    机器人:layout_marginTop =16DP
    机器人:SRC =@可绘制/下载/>

< ImageView的
    机器人:ID =@ + ID / imageView2
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignTop =@ + ID / imageView1
    机器人:layout_marginLeft =18dp
    机器人:layout_toRightOf =@ + ID / imageView1
    机器人:SRC =@可绘制/下载/>

< ImageView的
    机器人:ID =@ + ID / imageView3
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_below =@ + ID / imageView1
    机器人:layout_marginTop =18dp
    机器人:SRC =@可绘制/下载/>

< ImageView的
    机器人:ID =@ + ID / imageView5
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignLeft =@ + ID / imageView3
    机器人:layout_centerVertical =真
    机器人:SRC =@可绘制/下载/>

< ImageView的
    机器人:ID =@ + ID / imageView6
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignTop =@ + ID / imageView3
    机器人:SRC =@可绘制/下载/>

< ImageView的
    机器人:ID =@ + ID / imageView4
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_below =@ + ID / imageView5
    机器人:layout_marginTop =17dp
    机器人:SRC =@可绘制/下载/>

< ImageView的
    机器人:ID =@ + ID / imageView7
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignLeft =@ + ID / imageView2
    机器人:layout_alignTop =@ + ID / imageView5
    机器人:layout_marginLeft =10dp
    机器人:SRC =@可绘制/下载/>
< ImageView的
    机器人:ID =@ + ID / imageView8
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignLeft =@ + ID / imageView7
    机器人:layout_alignTop =@ + ID / imageView3
    机器人:SRC =@可绘制/下载/>

< / RelativeLayout的>
< / LinearLayout中>
< /滚动型>
 

I have a relative layout with multiple "imageview" and when I turn around the screen , the imageviews become disordered...so I decided to wrap it into a scroll view...but scroll view doesn't work !!! can any one help me by that ? I know that the right way is to design a gridview or listview...but since I had some questions and no one answered me in stackoverfloa , I decided to go this way. here is my xml code :

<?xml version="1.0" encoding="utf-8"?>


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:scrollbars="none" >


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <Button
        android:id="@+id/continuePizza"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="continue" />

    <Button
        android:id="@+id/finishP"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/continuePizza"
        android:layout_alignParentLeft="true"
        android:text="finish" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="16dp"
        android:src="@drawable/download" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/imageView1"
        android:layout_marginLeft="18dp"
        android:layout_toRightOf="@+id/imageView1"
        android:src="@drawable/download" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView1"
        android:layout_marginTop="18dp"
        android:src="@drawable/download" />

    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imageView3"
        android:layout_centerVertical="true"
        android:src="@drawable/download" />

    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/imageView3"
        android:src="@drawable/download" />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView5"
        android:layout_marginTop="17dp"
        android:src="@drawable/download" />

    <ImageView
        android:id="@+id/imageView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imageView2"
        android:layout_alignTop="@+id/imageView5"
        android:layout_marginLeft="10dp"
        android:src="@drawable/download" />
    <ImageView
        android:id="@+id/imageView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imageView7"
        android:layout_alignTop="@+id/imageView3"
        android:src="@drawable/download" />

</RelativeLayout>

</ScrollView>

解决方案

I experienced same problem with Relative Layout within Scroll View to overcome this i wrapped around my relative layout with a linear layout , try like this and also remove orientation from relative layout

<?xml version="1.0" encoding="utf-8"?>


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none" >

<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent">


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>


<Button
    android:id="@+id/continuePizza"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="continue" />

<Button
    android:id="@+id/finishP"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/continuePizza"
    android:layout_alignParentLeft="true"
    android:text="finish" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="16dp"
    android:src="@drawable/download" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/imageView1"
    android:layout_marginLeft="18dp"
    android:layout_toRightOf="@+id/imageView1"
    android:src="@drawable/download" />

<ImageView
    android:id="@+id/imageView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageView1"
    android:layout_marginTop="18dp"
    android:src="@drawable/download" />

<ImageView
    android:id="@+id/imageView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/imageView3"
    android:layout_centerVertical="true"
    android:src="@drawable/download" />

<ImageView
    android:id="@+id/imageView6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/imageView3"
    android:src="@drawable/download" />

<ImageView
    android:id="@+id/imageView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageView5"
    android:layout_marginTop="17dp"
    android:src="@drawable/download" />

<ImageView
    android:id="@+id/imageView7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/imageView2"
    android:layout_alignTop="@+id/imageView5"
    android:layout_marginLeft="10dp"
    android:src="@drawable/download" />
<ImageView
    android:id="@+id/imageView8"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/imageView7"
    android:layout_alignTop="@+id/imageView3"
    android:src="@drawable/download" />

</RelativeLayout>
</LinearLayout>
</ScrollView>

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

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