安卓RelativeLayout的:如何alignParentBottom包裹在一个滚动型的时候? [英] Android RelativeLayout : how to alignParentBottom when wrapped in a ScrollView?

查看:206
本文介绍了安卓RelativeLayout的:如何alignParentBottom包裹在一个滚动型的时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题似乎是,如果我有一个观点(如为myButton)一个RelativeLayout的设置alignParentBottom内 - (按照code以下) - 然后包裹RelativeLayout的用滚动视图(必需的,以便内容将能够看到在小屏幕上,或当方向将更改为横向) - 那么,当父底部是不可见的(例如,当改为横向)myButton的显示在页面的顶部 - 不是底部

如何可以对齐以便在屏幕的底部,并有它留在底部,即使是底部的滚动低于β

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



< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
 机器人:ID =@ + ID / topLayout
 机器人:layout_width =FILL_PARENT
 机器人:layout_height =FILL_PARENT>



......很多的意见和东西


<按钮机器人:layout_alignParentBottom =真
机器人:ID =@ + ID / myButton的
机器人:文本=点击我/>

< / RelativeLayout的>
< /滚动型>
 

解决方案

取按钮出了滚动型的,在一个线性布局总结两个滚动视图和按钮,设置滚动视图的高度0dip,并设置它的权重为1,不设置任何重量属性按钮,使滚动视图可以占用所有剩余空间仅保存按钮的空间的方式在底部。

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>

    <滚动型
        机器人:layout_width =match_parent
        机器人:layout_height =0dip
        机器人:layout_weight =1>
        <的LinearLayout
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:方向=横向>

        ....很多的意见...


        < / LinearLayout中>
    < /滚动型>

    <按钮
        机器人:ID =@ + ID /按钮1
        机器人:layout_width =match_parent
        机器人:layout_height =40dp
        机器人:文本=按钮/>

< / LinearLayout中>
 

The problem I am having seems to be that if I have a view (e.g. myButton) inside a RelativeLayout set to alignParentBottom - (as per the code below) - and then wrap the RelativeLayout with a scrollview (necessary so the content will be viewable on smaller screens or when orientation changes to landscape) - then, when the parent bottom is NOT visible (for example when changed to landscape orientation) myButton is displayed at the TOP of the page - NOT the bottom.

How can you align a view to the bottom of the screen and have it remain at the bottom even if the bottom is below the scroll?

<ScrollView
android:id="@+id/mainScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="true">



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/topLayout"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">



... lots of views and stuff


<Button android:layout_alignParentBottom="true" 
android:id="@+id/myButton"  
android:text="Click Me" />

</RelativeLayout>
</ScrollView>   

解决方案

Take the button out of the SCrollview, Wrap both the Scrollview and the Button in a Linear Layout, set the scrollview's height to 0dip and set it's weight to 1, do not set any weight property for the button, so the scrollview can occupy all the remaining space saving only the button's space way at the bottom.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ScrollView 
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

        ....lots of views...


        </LinearLayout>
    </ScrollView>

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:text="Button" />

</LinearLayout>

这篇关于安卓RelativeLayout的:如何alignParentBottom包裹在一个滚动型的时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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