困难滚动型和的LinearLayout [英] Difficulty with ScrollView and LinearLayout

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

问题描述

我试图做一个Android的布局:内部垂直的LinearLayout 3的组件。该中心部分是一个滚动型包含的TextView 。当的TextView 包含一个显著文字量(超过可容纳在屏幕上),在滚动型长所有的一直到屏幕的底部,显示滚动条,并推动最后一个组件,一个的LinearLayout 按钮里面,在屏幕上。

如果里面的文字的TextView 滚动型足够短,在屏幕底部的按钮被完全定位。

我想要实现的布局是:

中的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>

    < TextView的Andr​​oid的:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文字颜色=#FFFFFF
            机器人:layout_marginLeft =10dip
            机器人:layout_marginRight =10dip
            机器人:layout_marginTop =10dip
            机器人:layout_marginBottom =10dip
            机器人:文本=标题/>

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

        < TextView的机器人:ID =@ + ID /文
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:自动链接=网
                机器人:文字颜色=#FFFFFF
                机器人:后台=#444444
                机器人:填充=10dip/>

    < /滚动型>

    <的LinearLayout
            机器人:方向=横向
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT
            机器人:layout_weight =1>

        <的LinearLayout
                机器人:方向=横向
                机器人:layout_width =0dip
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_weight =1/>

        <按钮机器人:ID =@ + ID / login_button
                机器人:layout_width =0dip
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_gravity =底
                机器人:layout_weight =1
                机器人:文本=@字符串/ next_button/>

    < / LinearLayout中>

< / LinearLayout中>
 

解决方案

滚动视图是第二个视图对象,并设置为WRAP_CONTENT,这比在屏幕上。

我推荐一个RelativeLayout的。第一热门的TextView与安卓alignParentTop =真正的,底部的LinearLayout接下来与安卓alignParentBottom =真正的而最后在XML与所列数值的滚动视图机器人:alignBelow =@ ID / whatYouCallTheHeader

此将调整在屏幕的底部的底栏,和在顶部的标题,不论大小。然后滚动视图将拥有自己的一席之地,页眉和页脚已放置后。

I'm trying to make an Android layout: 3 components inside a vertical LinearLayout. The center component is a ScrollView that contains a TextView. When the TextView contains a significant amount of text (more than can fit on the screen), the ScrollView grows all the way to the bottom of the screen, shows scrollbars, and pushes the last component, a LinearLayout with a Button inside, off the screen.

If the text inside the TextView inside the ScrollView is short enough, the button at the bottom of the screen is positioned perfectly.

The layout I'm trying to achieve is:

The XML for the layout I've written is:

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

    <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:layout_marginTop="10dip"
            android:layout_marginBottom="10dip"
            android:text="Title />

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

        <TextView android:id="@+id/text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:autoLink="web"
                android:textColor="#FFFFFF"
                android:background="#444444"
                android:padding="10dip" />

    </ScrollView>

    <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1">

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

        <Button android:id="@+id/login_button"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_weight="1"
                android:text="@string/next_button"/>

    </LinearLayout>

</LinearLayout>

解决方案

The scrollview is the second view object and is set to wrap_content, which is more than the screen.

I recommend a RelativeLayout. Top textview first with android:alignParentTop="true", the bottom LinearLayout next with android:alignParentBottom="true" and the scrollview listed last in the xml with the value android:alignBelow="@id/whatYouCallTheHeader.

This will align the bottom bar at the bottom of the screen, and the header at the top, no matter the size. Then the scrollview will have its own place, after the header and footer have been placed.

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

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