【问题标题】:I need to design an android activity with a scrollview我需要设计一个带有滚动视图的 android 活动
【发布时间】:2016-06-08 22:24:25
【问题描述】:

如何在其中插入滚动视图,并且仍然保留我的应用程序上的标题?此外,所有教程似乎都要求您切换到 LinearLayout,而 LinearLayout 让我很难格式化我需要包含在活动中的所有按钮和文本框。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="washingtondeli.groupboxlunchesestimateandordering.CapitolhillActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Capitol Hill Picnic Box Lunch"
        android:id="@+id/capitolhilltitle"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

【问题讨论】:

  • 似乎是什么问题?只需将您的 TextView 包装在一个滚动视图中。此外,习惯使用 LinearLayouts,因为它们在不同设备上的外观通常比 RelativeLayouts 更加一致。

标签: android xml android-studio android-scrollview


【解决方案1】:

第 1 步:将 ScrollView 设为您的根布局

第 2 步将 LinearLayout 添加到您的 ScrollView

记住,一个 ScrollView 只接受 1 个孩子

然后只需在您的 LinearLayout 中添加您的按钮 - 顺便说一下,它可能有其他 LinearLayouts 来支持不同的布局样式,然后您有相应的权重来定位您的项目!

您还可以查看其他选项。哦,差点忘了这一点:阅读一些关于这方面的教程以帮助您入门!

我希望这会有所帮助!

【讨论】:

  • 感谢您的帮助。现在我正在尝试添加按钮,因为我在线性视图中,它不再让我拖放东西
【解决方案2】:

您可以在滚动视图中使用相对布局, 这是一个示例,用于具有固定标题的相对布局的滚动视图

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


    <TextView
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:text="Header"
        android:textColor="#ffffff"
        android:textSize="22dp" />

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_below="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="0dp"
        android:fillViewport="true" >

        <RelativeLayout
            android:id="@+id/filt_top"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:animateLayoutChanges="true" >

            //your scrollable contents here

        </RelativeLayout>

    </ScrollView>

    </RelativeLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多