我应该为这个Android UI使用什么布局

时间:2013-02-04 16:22:19

标签: android-layout android-scrollview

我想在android

中制作类似的东西
-----------------------------
|                            |
|                            |
|        arrow up here       |
|----------------------------|
|                            |
|     scroll-able with       |
|     components             |
|----------------------------|
|        arrow down here     |
|                            |
|                            |
-----------------------------

中间的滚动功能无法使用ScrollView? 向上箭头应向上滚动中间的滚动(如果这个布局真的是滚动视图) 并且向下箭头向下但是向下

背景应该修复,中间滚动应该只滚动组件是不可能的? 我应该使用什么布局? 提前谢谢。

2 个答案:

答案 0 :(得分:1)

如果你真的想使用scrollview(而不是ListView),这是你的布局。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="up"
        android:text="UP" />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <!-- ADD YOUR COMPONENTS HERE -->

        </LinearLayout>
    </ScrollView>

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="down"
        android:text="DOWN" />

</LinearLayout>

这就是如何管理活动中的“向上”和“向下”事件。添加以下方法:

public void up(View v) {
    ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView1);
    scrollView.scrollBy(0, +20);
}

public void down(View v) {
    ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView1);
    scrollView.scrollBy(0, -20);
}

在这个例子中,我只是滚动了20个像素。调整这些值以获得所需的值(例如,在滚动视图中间滚动,或滚动可见滚动视图高度的一半)。

答案 1 :(得分:0)

在中间延迟你需要的东西。您可以拥有<ScrollView>并在滚动视图中构建xml。或者您可以按照建议执行操作并使用listView。如果没有更多信息,则更难以指导您。

相关问题