【发布时间】:2014-11-05 23:01:23
【问题描述】:
我有 3 个按钮,滚动视图包含文本和图像。 我只想要图像和文本的滚动视图效果,并且我的 3 个按钮固定在滚动视图上,我该怎么做?
【问题讨论】:
标签: android android-layout android-scrollview xml-layout
我有 3 个按钮,滚动视图包含文本和图像。 我只想要图像和文本的滚动视图效果,并且我的 3 个按钮固定在滚动视图上,我该怎么做?
【问题讨论】:
标签: android android-layout android-scrollview xml-layout
使用FrameLayout。
下面展示了带有图像的ScrollView 上方带有三个按钮的顶栏示例。
FrameLayout 会按照声明的顺序渲染他们的孩子。对于下面的示例,首先渲染ScrollView,最后渲染LinearLayout 按钮栏。这会将栏放置在滚动视图上方并提供所需的效果。
ScrollView 之所以有LinearLayout 作为孩子,是因为他们只能有一个孩子。
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
</FrameLayout>
【讨论】:
layout_gravity="bottom"。