【发布时间】:2023-04-09 18:19:01
【问题描述】:
我设计了一个布局,其中数据将来自 recyclerview。我面临的问题是我无法对齐项目。
下面是sn-p图片。
这是我的布局
<?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="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:background="@color/white"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp">
<TextView
android:gravity="center"
android:text="prnce"
android:textColor="@color/black"
android:backgroundTint="@color/white"
android:id="@+id/groupname"
android:layout_weight="1"
android:textAlignment="center"
android:layout_width="wrap_content"
android:layout_height="match_parent">
</TextView>
<TextView
android:gravity="center"
android:text="1"
android:textColor="@color/black"
android:backgroundTint="@color/white"
android:id="@+id/groupCount"
android:textAlignment="center"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<ImageButton
android:backgroundTint="@color/white"
android:src="@drawable/myhomegrey"
android:id="@+id/homeWindow"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="match_parent">
</ImageButton>
<ImageButton
android:backgroundTint="@color/white"
android:src="@drawable/stargrey"
android:id="@+id/favorite"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="match_parent">
</ImageButton>
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
如何将每个项目对齐在中心,以便它们可以排成一行,这样如果 textview 文本大小增加或减少,它不应该影响其他布局的对齐方式
【问题讨论】:
标签: java android-studio android-linearlayout cardview