使用Constraint Layout代替Linear Layout,并且在横向模式下检查你的布局,如果布局不符合你的要求,也可以在横向模式下为视图做不同的安排。https:/developer.android.comtrainingmultiscreenscreensizes。
这是修改后的文件(如果有人能用的话)
<?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:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fcfcfc"
android:gravity="center"
tools:context="com.example.homedashboard.MainActivity">
<androidx.cardview.widget.CardView
android:id="@+id/bank_card"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="46dp"
android:layout_marginLeft="46dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
app:layout_constraintBottom_toTopOf="@+id/add_card"
app:layout_constraintEnd_toStartOf="@+id/ideas_card"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="@drawable/cerclebackgroundpurple"
android:padding="10dp"
android:src="@drawable/ic_attach_money_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Banking"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="10dp"
android:background="@color/lightgray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:text="Check your bank activities"
android:textColor="@android:color/darker_gray" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/ideas_card"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="25dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="20dp"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
app:layout_constraintBottom_toTopOf="@+id/links_card"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/bank_card"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="@drawable/cerclebackgroundpink"
android:padding="10dp"
android:src="@drawable/ic_lightbulb_outline_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Ideas"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="10dp"
android:background="@color/lightgray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:text="Check your bank activities"
android:textColor="@android:color/darker_gray" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/add_card"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="46dp"
android:layout_marginLeft="46dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="16dp"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
app:layout_constraintBottom_toTopOf="@+id/wifi_card"
app:layout_constraintEnd_toStartOf="@+id/links_card"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bank_card">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="@drawable/cerclebackgroundgreen"
android:padding="10dp"
android:src="@drawable/ic_control_point_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Add"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="10dp"
android:background="@color/lightgray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:text="Check your bank activities"
android:textColor="@android:color/darker_gray" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/links_card"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="25dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="16dp"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
app:layout_constraintBottom_toTopOf="@+id/wifi_card"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/add_card"
app:layout_constraintTop_toBottomOf="@+id/ideas_card">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="@drawable/cerclebackgroundyello"
android:padding="10dp"
android:src="@drawable/ic_attach_file_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Links"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="10dp"
android:background="@color/lightgray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:text="Check your bank activities"
android:textColor="@android:color/darker_gray" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/wifi_card"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="7dp"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/links_card"
app:layout_constraintStart_toStartOf="@+id/add_card"
app:layout_constraintTop_toBottomOf="@+id/add_card">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="@drawable/cerclebackgroundpurple"
android:padding="10dp"
android:src="@drawable/ic_wifi_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Wifi"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="10dp"
android:background="@color/lightgray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:text="Check your bank activities"
android:textColor="@android:color/darker_gray" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>