1

我正在尝试创建以下屏幕布局:

  1. 一行包含一些 TextView
  2. 用户操作将在其中添加或删除 View 的滚动视图
  3. 纽扣线。

我对 1. 或 3. 没有问题。但是 2. 给我带来了麻烦。我的方案是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/mainX"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" 
  android:orientation="vertical">
  <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/labels" 
    android:layout_weight="1">
  <!--Some text view of various sizes -->
  </LinearLayout>
  <ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/dataScroll">
    <LinearLayout 
      android:id="@+id/dataShow" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content">
    </LinearLayout>
  </ScrollView>
  <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/buttons" 
    android:layout_weight="1">
  <!--some buttons-->
  </LinearLayout>
</LinearLayout>

当我运行程序时,按钮行位于屏幕中间,当我向屏幕添加元素时(使用 dataShow 布局上的 addView),第一个添加没有问题,但之后我不知道怎么了。

谢谢

4

2 回答 2

0

我不确定您要做什么。

似乎您想将项目动态添加到 dataShow 布局中。您应该为 dataShow 布局使用ListView(垂直滚动)或Gallery (水平滚动),而不是使用包含 LinearLayout 的 ScrollView。这将提供滚动功能并允许您将项目动态添加到列表/画廊。

于 2011-06-11T20:18:42.630 回答
0

尝试使用RelativeLayout,然后在顶部对齐页眉,在底部对齐页脚。设置 ScrollView paddingBottom。

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    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:background="@color/colorPrimary"
        android:paddingBottom="10dp"
        android:paddingTop="10dp"
        android:text="text"
        android:textAlignment="center"
        android:layout_centerHorizontal="true"
        android:layout_alignParentTop="true"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/header"
        android:layout_above="@+id/footer"
        android:paddingBottom="100dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="center main content"
            android:textAlignment="center"
            android:layout_centerHorizontal="true"
            android:layout_alignParentTop="true"/>

    </ScrollView>

    <RelativeLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@color/colorPrimary"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="text"
            android:textAlignment="center"
            android:layout_centerHorizontal="true"
            android:layout_alignParentTop="true"/>

    </RelativeLayout>
</RelativeLayout>
于 2018-06-03T15:31:03.033 回答