【问题标题】:android layout stuffandroid布局的东西
【发布时间】:2011-06-10 15:19:11
【问题描述】:

如果在滚动视图中我有一个包含两个文本视图的相对布局,并且其中一个文本视图具有属性 android:layout_alignParentBottom="true"。可以在屏幕底部对齐这个textview吗?

    <?xml version="1.0" encoding="utf-8"?>
<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">

    <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="blabla"/>

    <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="blabla2"/>

</RelativeLayout>

</ScrollView>

【问题讨论】:

    标签: android scrollview android-relativelayout


    【解决方案1】:

    如果你想在底部对齐 TextView,并且 UI 的其余部分是可滚动的。那么你的布局应该是这样的。

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <ScrollView android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <RelativeLayout android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <TextView android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:text="blabla" />
        </RelativeLayout>
    </ScrollView>
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_alignParentBottom="true"
        android:text="blabla2" />
        </RelativeLayout>
    

    希望这会有所帮助。

    【讨论】:

    • 我希望我的所有项目都可以滚动,因为将来页面上可能会出现多个项目,但我必须在屏幕底部保留一个项目
    • 如果我错了,请纠正我,我从您的评论中了解到,您想要 n-1 个可滚动的项目和第 n 个项目(在上述情况下为 blabla2)应该始终位于底部屏幕,意味着对用户始终可见。如果这是您的情况,那么您只需要在 ScrollView 中提到的 RelativeLayout 中添加所有 n-1 个视图。因此,n-1 个视图将是可滚动的,并且第 n 个视图将始终固定在底部。
    • 所以在我看来必须是 6 项。在纵向中,最后一个必须位于屏幕底部(并且它们都适合 hdpi 设备的纵向模式,从 mdpi 它们不适合)但在横向上它们不适合所以这就是为什么我需要将它们放入滚动视图...
    • 好吧,我明白你的意思了。为此,您应该查看此link。并寻找 onConfigurationChanged() 并且您还应该尝试在 google 上搜索提到的 layout-land 和 layout-port here。希望这可以帮助您解决问题。
    猜你喜欢
    • 2019-02-10
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 2013-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多