我试图获取一个ListView来显示数据库项,但这些项到处都是

时间:2019-03-14 09:49:56

标签: android xml android-layout android-listview

我有一个学校项目,需要为此制作一个android应用程序。 我正在使用Android Studio和Java对其进行编程。我有一个列表视图,该列表视图显示数据库中的项目,但列表视图中的项目不在我想要的位置。

It currently looks like thisBut i Want it to look like this

我非常感谢您的帮助。 我不知道我的问题在哪里,所以我将包括所有相关代码。 对不起,如果我的英语不好,我不会说英语。 这是我第一次用JAVA编写程序,所以如果您看到一些菜鸟错误,请也告诉我

* edit:我新的和更新的content_Main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/activity_main">

<android.support.v7.widget.CardView
    android:layout_width="409dp"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    app:layout_constraintBottom_toTopOf="@+id/listview"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0">

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

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="58dp">

            <TextView
                android:id="@+id/DatumVieuw"
                android:layout_width="match_parent"
                android:layout_height="57dp"
                android:layout_marginBottom="108dp"
                android:textAlignment="center"
                android:textSize="30sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0"
                tools:text="Halloo" />
        </TableRow>

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

            <TextView
                android:id="@+id/watVieuw"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:textSize="24sp"
                app:layout_constraintEnd_toEndOf="parent"
                tools:layout_editor_absoluteY="40dp"
                tools:text="Mijn" />

        </TableRow>

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

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/totTijd"
                    android:layout_width="wrap_content"
                    android:layout_height="22dp"
                    android:textAlignment="textEnd"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/watVieuw"
                    tools:text="Is" />

                <TextView
                    android:id="@+id/vanTijd"
                    android:layout_width="58dp"
                    android:layout_height="23dp"
                    android:layout_marginEnd="340dp"
                    app:layout_constraintEnd_toStartOf="@+id/totTijd"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/watVieuw"
                    tools:text="Naam" />
            </android.support.constraint.ConstraintLayout>

        </TableRow>

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

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/TotDatum"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    tools:text="Ajaouin" />

                <TextView
                    android:id="@+id/VanDatum"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAlignment="viewStart"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    tools:text="Nataro" />
            </android.support.constraint.ConstraintLayout>

        </TableRow>
    </LinearLayout>
</android.support.v7.widget.CardView>

<Button
    android:id="@+id/button"
    android:layout_width="93dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="532dp"
    android:layout_marginEnd="144dp"
    android:onClick="btnClick"
    android:text="Button"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<ListView
    android:id="@+id/listview"
    android:layout_width="wrap_content"
    android:layout_height="324dp"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="216dp"
    android:dividerHeight="10.0sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.375"
    app:layout_constraintStart_toStartOf="parent" />

 </android.support.constraint.ConstraintLayout>

*编辑:未对齐的项目:

<TextView
                            android:id="@+id/totTijd"
                            android:layout_width="wrap_content"
                            android:layout_height="22dp"
                            android:textAlignment="textEnd"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintTop_toBottomOf="@+id/watVieuw"
                            tools:text="Is" />

                        <TextView
                            android:id="@+id/vanTijd"
                            android:layout_width="58dp"
                            android:layout_height="23dp"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@+id/watVieuw"
                            tools:text="Naam" />

                        <TextView
                            android:id="@+id/VanDatum"
                            android:layout_width="wrap_content"
                            android:layout_height="25dp"
                            android:textAlignment="viewStart"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            tools:text="Nataro" />

                        <TextView
                            android:id="@+id/watVieuw"
                            android:layout_width="412dp"
                            android:layout_height="47dp"
                            android:textAlignment="textStart"
                            android:textSize="24sp"
                            app:layout_constraintEnd_toEndOf="parent"
                            tools:layout_editor_absoluteY="40dp"
                            tools:text="Mijn" />

                        <TextView
                            android:id="@+id/DatumVieuw"
                            android:layout_width="419dp"
                            android:layout_height="40dp"
                            android:layout_marginBottom="108dp"
                            android:text="Halloo"
                            android:textAlignment="center"
                            android:textSize="30sp"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintHorizontal_bias="1.0"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent"
                            app:layout_constraintVertical_bias="0.0"
                            tools:text="Halloo" />

                        <TextView
                            android:id="@+id/TotDatum"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintEnd_toEndOf="parent"
                            tools:text="Ajaouin" />

I have this as my component tree

* edit:我修复了组件树,现在可以正常工作了 fixed comp tree

但是现在我有一个新问题 the new problem

*编辑:新的xml代码

 <android.support.v7.widget.CardView
    android:layout_width="409dp"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    app:layout_constraintBottom_toTopOf="@+id/listview"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0">

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

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="58dp">

            <TextView
                android:id="@+id/DatumVieuw"
                android:layout_width="match_parent"
                android:layout_height="57dp"
                android:layout_marginBottom="108dp"
                android:textAlignment="center"
                android:textSize="30sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0"
                tools:text="Halloo" />
        </TableRow>

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

            <TextView
                android:id="@+id/watVieuw"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:textSize="24sp"
                app:layout_constraintEnd_toEndOf="parent"
                tools:layout_editor_absoluteY="40dp"
                tools:text="Mijn" />

        </TableRow>

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

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/totTijd"
                    android:layout_width="wrap_content"
                    android:layout_height="22dp"
                    android:textAlignment="textEnd"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/watVieuw"
                    tools:text="Is" />

                <TextView
                    android:id="@+id/vanTijd"
                    android:layout_width="58dp"
                    android:layout_height="23dp"
                    android:layout_marginEnd="340dp"
                    app:layout_constraintEnd_toStartOf="@+id/totTijd"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/watVieuw"
                    tools:text="Naam" />
            </android.support.constraint.ConstraintLayout>

        </TableRow>

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

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/TotDatum"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    tools:text="Ajaouin" />

                <TextView
                    android:id="@+id/VanDatum"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAlignment="viewStart"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    tools:text="Nataro" />
            </android.support.constraint.ConstraintLayout>

        </TableRow>
    </LinearLayout>
</android.support.v7.widget.CardView>

我自己添加了一个受约束的布局,因为我的商品无法保持其位置

0 个答案:

没有答案