Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何显示相关布局的列表?_Android_User Interface - Fatal编程技术网

Android 如何显示相关布局的列表?

Android 如何显示相关布局的列表?,android,user-interface,Android,User Interface,我遇到了一个问题,我是一名网络开发人员,我习惯了CSS,我非常擅长CSS,我以为Android设计也会如此,但我真的很不开心,我花了几乎半天的时间只设计顶部菜单,并在其下方放置两个按钮,我甚至认为我做得不对,现在我有一个区域,我在右侧显示一个图像、用户名和按钮,下面是它的外观: <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap

我遇到了一个问题,我是一名网络开发人员,我习惯了CSS,我非常擅长CSS,我以为Android设计也会如此,但我真的很不开心,我花了几乎半天的时间只设计顶部菜单,并在其下方放置两个按钮,我甚至认为我做得不对,现在我有一个区域,我在右侧显示一个图像、用户名和按钮,下面是它的外观:

     <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="70dp">
                <Button
                    android:id="@+id/button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Ajouter"
                    android:layout_marginRight="40px"
                    android:layout_marginTop="30px"

                    />
                <LinearLayout
                    android:orientation="horizontal"
                    android:id="@+id/bun"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="something"
                    android:layout_alignParentLeft="true"
                    android:layout_margin="10px"
                    >
                    <TextView
                        android:layout_width="350px"
                        android:layout_height="30dp"
                        android:layout_marginTop="45px"
                        android:layout_marginLeft="0px"

                        android:textSize="22sp"
                        tools:text="AkkaBook"></TextView>
                    <ImageView
                        android:layout_width="100px"
                        android:layout_height="100px"
                        android:layout_marginTop="40px"
                        android:layout_marginRight="40px"
                        android:layout_marginLeft="40px"
                        android:id="@+id/profgilImg"
                        android:background="@color/colorPrimary"></ImageView>

                </LinearLayout>


            </RelativeLayout>

        </RelativeLayout> 

它是一个必须包含许多相对布局的相对布局,每个子相对布局都有内容(image-username-button)。我只做了一个,但是当我复制并粘贴代码以得到一个完整的列表时,一切都开始变得丑陋起来

以下是我所做的事情:

我想要的是一份清单:


任何帮助都将不胜感激。

您应该使用RecyclerView或ListView,它具有带有相关布局项的适配器


您应该使用RecyclerView或ListView,它具有带有相对布局项的适配器


您必须使用两种不同的布局。因为我认为您有一个主布局,其中包括recyclerView和recyclerView的项目布局。你的布局应该是这样的

主布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:id="@+id/linearLayoutHeader"
        android:gravity="center"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="LISTE DES AMIS"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="SUGGESTIONS"/>

    </LinearLayout>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/linearLayoutHeader"
        app:layout_constraintBottom_toBottomOf="parent">

     <!-- put your recyclerView here -->

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

回收视图项

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#e1e1e2">

    <View
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginStart="8dp"
        android:id="@+id/viewView"
        app:layout_constraintStart_toStartOf="parent"
        android:background="@color/colorPrimaryDark"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toEndOf="@id/viewView"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginStart="8dp"
        android:text="Akka Book"/>

    <Button
        android:layout_width="50dp"
        android:layout_height="30dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginEnd="8dp"
        android:text="AJOUTER"/>

</androidx.constraintlayout.widget.ConstraintLayout>


更喜欢ConstraintLayout,而不是RelativeLayout,以获得更好的性能。这就是你必须使用两种不同的布局。因为我认为你有一个主布局,其中包括一个recyclerView和一个recyclerView的项目布局。你的布局应该是这样的

主布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:id="@+id/linearLayoutHeader"
        android:gravity="center"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="LISTE DES AMIS"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="SUGGESTIONS"/>

    </LinearLayout>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/linearLayoutHeader"
        app:layout_constraintBottom_toBottomOf="parent">

     <!-- put your recyclerView here -->

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

回收视图项

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#e1e1e2">

    <View
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginStart="8dp"
        android:id="@+id/viewView"
        app:layout_constraintStart_toStartOf="parent"
        android:background="@color/colorPrimaryDark"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toEndOf="@id/viewView"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginStart="8dp"
        android:text="Akka Book"/>

    <Button
        android:layout_width="50dp"
        android:layout_height="30dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginEnd="8dp"
        android:text="AJOUTER"/>

</androidx.constraintlayout.widget.ConstraintLayout>


更喜欢ConstraintLayout而不是RelativeLayout以获得更好的性能。这就是所有的

回收器视图将是您最好的选择,因为这样您可以动态添加数据一次,它将自动用新数据填充视图,这将更容易。试一试:有没有人有任何资源可以帮助web开发人员了解android布局?@KennyJohnJacob我一直梦想着这一点,因为轻松找到这些东西非常重要,但我总是遇到这样的问题:(回收者视图是你最好的选择,因为这样你可以动态添加数据一次,它会自动用新数据填充视图,这会更容易。试试看:有没有人有任何资源可以帮助web开发人员过渡到理解安卓布局?@KennyJohnJacob我一直梦想着这样做,因为它是很容易找到这些东西很重要,但我总是有问题:(