我在Android Studio上查看布局时遇到问题
我会尽量简短。 当我在某些设备上启动我的应用程序时,我在CardView的排列上遇到了问题。 我认为这种情况发生在较旧的设备上。我在下面的图片中添加,在前两个中问题不存在,在其他两个中是的 我尝试了一切,在Android studio中,所有API都能正确显示(20-29) java代码尚未更改 三星j5 2016:我在Android Studio上查看布局时遇到问题,android,android-studio,layout,Android,Android Studio,Layout,我会尽量简短。 当我在某些设备上启动我的应用程序时,我在CardView的排列上遇到了问题。 我认为这种情况发生在较旧的设备上。我在下面的图片中添加,在前两个中问题不存在,在其他两个中是的 我尝试了一切,在Android studio中,所有API都能正确显示(20-29) java代码尚未更改 三星j5 2016: 小米红米5加: 平板电脑联想: Wiko Rainbow lite: 您好,请尝试以下代码。我已经更新了。请试试这个 <ScrollView xmlns:androi
小米红米5加:
平板电脑联想:
Wiko Rainbow lite:
您好,请尝试以下代码。我已经更新了。请试试这个
<ScrollView 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:background="@android:color/black"
tools:context=".Capitoli">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="32dp"
android:layout_marginRight="20dp">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hi"
android:textColor="#FFF"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_marginTop="6dp"
android:text="58 "
android:textColor="#FFF"
android:textSize="14sp" />
<ImageView
android:layout_width="62dp"
android:layout_height="62dp"
android:layout_alignParentRight="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:weightSum="2"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:layout_weight="1"
app:cardCornerRadius="12dp"
app:cardElevation="6dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/whale" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="capitolo 1"
android:textColor="@color/viola"
android:textSize="18sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:layout_weight="1"
app:cardCornerRadius="12dp"
app:cardElevation="6dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/whale" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="capitolo 1"
android:textColor="@color/viola"
android:textSize="18sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
</ScrollView>
欢迎来到社区。我建议您使用ConstraintLayout(使用百分比)或LinearLayout(使用权重属性)重新编写xml代码。尝试在每个CardView中使用android:layout\u width=“0dp”
<ScrollView 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:background="@android:color/black"
tools:context=".Capitoli">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="32dp"
android:layout_marginRight="20dp">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hi"
android:textColor="#FFF"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_marginTop="6dp"
android:text="58 "
android:textColor="#FFF"
android:textSize="14sp" />
<ImageView
android:layout_width="62dp"
android:layout_height="62dp"
android:layout_alignParentRight="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:weightSum="2"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:layout_weight="1"
app:cardCornerRadius="12dp"
app:cardElevation="6dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/whale" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="capitolo 1"
android:textColor="@color/viola"
android:textSize="18sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:layout_weight="1"
app:cardCornerRadius="12dp"
app:cardElevation="6dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/whale" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="capitolo 1"
android:textColor="@color/viola"
android:textSize="18sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
</ScrollView>