Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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 studio 以编程方式以不同方式对齐RecycleWeber中的每个项目(自定义网格布局)_Android Studio_Android Recyclerview_Grid Layout_Android Gridlayout - Fatal编程技术网

Android studio 以编程方式以不同方式对齐RecycleWeber中的每个项目(自定义网格布局)

Android studio 以编程方式以不同方式对齐RecycleWeber中的每个项目(自定义网格布局),android-studio,android-recyclerview,grid-layout,android-gridlayout,Android Studio,Android Recyclerview,Grid Layout,Android Gridlayout,我已经使用自定义网格布局实现了recycler viewer,当行索引>1时,每行有一个标题和3个项目 我的问题是如何以编程方式将每行中的三个项目与标题中某个元素的宽度对齐: 例如,如何确定所有自由狗适合hello world框(红线)的宽度,并在下方精确对齐,以获得这样的结果(通过图像编辑工具编辑): 有什么想法吗 标题xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayo

我已经使用自定义网格布局实现了recycler viewer,当行索引>1时,每行有一个标题和3个项目

我的问题是如何以编程方式将每行中的三个项目与标题中某个元素的宽度对齐:

例如,如何确定所有自由狗适合hello world框(红线)的宽度,并在下方精确对齐,以获得这样的结果(通过图像编辑工具编辑):

有什么想法吗

标题xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="wrap_content"
    android:background="@color/lightgrey"
    android:orientation="vertical">     
     
     <LinearLayout
                android:id="@+id/aboutme"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/circularbordersolid"
                android:orientation="vertical"
                android:padding="16dp">

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

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

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:fontFamily="@font/proximanovaregular"
                            android:text="@string/hello"
                            android:textSize="17sp"
                            android:textStyle="bold" />

                        <Space
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginEnd="10dp"
                            android:fontFamily="@font/proximanovaregular"
                            android:text="Edit"
                            android:textColor="#FFCF66"
                            android:textSize="14sp" />
                    </LinearLayout>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:text="@string/value" />
                </LinearLayout>

            </LinearLayout>
</RelativeLayout>

图像xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="wrap_content"
    android:layout_height="wrap_content"

    android:background="@color/grey">

    <androidx.cardview.widget.CardView
        android:id="@+id/recipeCard"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/grey"
        app:cardCornerRadius="15dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ImageView
            android:id="@+id/imageViewRecipe"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="1dp"
            android:layout_gravity="right"
            android:layout_marginBottom="0dp"
            android:background="@color/grey"
            app:srcCompat="@drawable/dog" />
    </androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>

谢谢大家!