我需要设计一个带有滚动视图的 android activity
I need to design an android activity with a scrollview
如何向其中插入滚动视图,同时仍保留应用程序中的页眉?此外,所有教程似乎都要求您切换到 LinearLayout,而 LinearLayout 让我很难格式化我需要包含在 activity.
中的所有按钮和文本框。
<?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>
第 1 步:将 ScrollView 设为根布局
步骤 2 将 LinearLayout 添加到您的 ScrollView
记住,一个 ScrollView 只接受 1 个 Child
然后只需将您的按钮添加到您的 LinearLayout 中 - 顺便说一句,它可以有其他 LinearLayouts 来支持不同的布局样式,然后您有权重来相应地定位您的项目!
您还可以查看其他选项。哦,差点忘了这个:阅读一些这方面的教程来帮助你入门!
希望对您有所帮助!
您可以在滚动视图中使用相对布局,
这是一个示例,用于具有固定 Header
的相对布局的滚动视图
<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>
如何向其中插入滚动视图,同时仍保留应用程序中的页眉?此外,所有教程似乎都要求您切换到 LinearLayout,而 LinearLayout 让我很难格式化我需要包含在 activity.
中的所有按钮和文本框。<?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>
第 1 步:将 ScrollView 设为根布局
步骤 2 将 LinearLayout 添加到您的 ScrollView
记住,一个 ScrollView 只接受 1 个 Child
然后只需将您的按钮添加到您的 LinearLayout 中 - 顺便说一句,它可以有其他 LinearLayouts 来支持不同的布局样式,然后您有权重来相应地定位您的项目!
您还可以查看其他选项。哦,差点忘了这个:阅读一些这方面的教程来帮助你入门!
希望对您有所帮助!
您可以在滚动视图中使用相对布局, 这是一个示例,用于具有固定 Header
的相对布局的滚动视图 <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>