java - 应用程序设计问题: scroll and amount problems

标签 java android architecture

我是 StackOverflow 的新手,我不太确定这是否正确,但我想为我父亲的公司制作一个 Android 应用程序,他是 Bed&Breakfirst 的所有者,他想要一个应用程序来跟踪消费情况。我规划了一个产品列表的界面,所有的消费都可以这样选择:

/image/G5JhR.jpg

现在的问题是我们需要能够添加和删除产品。否则我会这样做:

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget46"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:id="@+id/widget47"
android:layout_width="48dp"
android:layout_height="wrap_content"
android:text="Button"
android:layout_x="267dp"
android:layout_y="2dp" />
<Button
android:id="@+id/widget52"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_x="266dp"
android:layout_y="43dp" />
<TextView
android:id="@+id/widget53"
android:layout_width="253dp"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_x="9dp"
android:layout_y="10dp" />
<TextView
android:id="@+id/widget54"
android:layout_width="251dp"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_x="8dp"
android:layout_y="50dp" />
<Button
android:id="@+id/widget55"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_x="267dp"
android:layout_y="85dp" />
<Button
android:id="@+id/widget56"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_x="267dp"
android:layout_y="128dp" />
<TextView
android:id="@+id/widget57"
android:layout_width="259dp"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_x="2dp"
android:layout_y="92dp" />
<TextView
android:id="@+id/widget58"
android:layout_width="256dp"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_x="6dp"
android:layout_y="136dp" />
</AbsoluteLayout>

但只有当您知道自己拥有的产品数量时才能做到这一点。但我们需要添加和删除产品(不需要编辑。)。

此外,如果我们添加许多产品以适应屏幕,我想制作一个滚动选项,可以滚动浏览所有类似的产品。

有什么办法可以做到这两件事吗?还是不可能?

最佳答案

A1:

使用TableLayout(或GridLayout等)和页面更改按钮。 (这更容易。)

在此模式中,表格(布局中)具有固定计数的行。
将 OnClickListener 设置为下一个/上一个按钮以更新每个单元格( TextView )文本。
(例如:第1页:显​​示第0至4行的产品名称,第2页:显示第5至9行)
单元格 TextView 旁边的每个按钮的 OnClickListener 也需要修改。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/text_01"
                android:layout_width="@dimen/text_view_width"
                android:layout_height="wrap_content"
                android:text="cell 01" />

            <Button
                android:id="@+id/button_01"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />
        </TableRow>

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/text_02"
                android:layout_width="@dimen/text_view_width"
                android:layout_height="wrap_content"
                android:text="cell 02" />

            <Button
                android:id="@+id/button_02"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />
        </TableRow>

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/text_03"
                android:layout_width="@dimen/text_view_width"
                android:layout_height="wrap_content"
                android:text="cell 03" />

            <Button
                android:id="@+id/button_03"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />
        </TableRow>

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/text_04"
                android:layout_width="@dimen/text_view_width"
                android:layout_height="wrap_content"
                android:text="cell 04" />

            <Button
                android:id="@+id/button_04"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />
        </TableRow>

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/text_05"
                android:layout_width="@dimen/text_view_width"
                android:layout_height="wrap_content"
                android:text="cell 05" />

            <Button
                android:id="@+id/button_05"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />
        </TableRow>
    </TableLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

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

        <TextView
            android:id="@+id/textView1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Next" />
    </LinearLayout>

</LinearLayout>
<小时/>

A2:

使用内部包含TableLayout(或GridLayout等)的ScrollView。

在此模式中,必须更改表(布局中)行数以适合您的数据计数。
(在代码中创建/删除 TableRows 并从表中添加/删除它们)

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/text_01"
                android:layout_width="@dimen/text_view_width"
                android:layout_height="wrap_content"
                android:text="cell 01" />

            <Button
                android:id="@+id/button_01"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/text_02"
                android:layout_width="@dimen/text_view_width"
                android:layout_height="wrap_content"
                android:text="cell 02" />

            <Button
                android:id="@+id/button_02"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />
        </TableRow>
    </TableLayout>

</ScrollView>
<小时/>

对于 A1 和 A2:

res/values/dimens.xml

<resources>
    <dimen name="text_view_width">250dp</dimen>
</resources>

关于java - 应用程序设计问题: scroll and amount problems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24734537/

相关文章:

java - 通知依赖项解析监听器失败

java - 程序编译,但运行时数组越界?

JavaMail 发送后删除 Content-Length header

android - 如何为 Android 应用程序的密码实现 Smart Lock

android - 如果我因为要转为正式版而关闭 Play 商店中的公开测试版程序,我的应用程序的用户会怎样?

android - TextView 的填充应用于线性布局中的其他 View

security - 基于用户或组成员身份的微服务架构中的实体级访问限制

java - 格式化 Java MessageFormat 文本时出现 IllegalArgumentException

architecture - Redis 配置

node.js - 用动态/脚本语言构建松散耦合系统的设计模式