【发布时间】:2021-02-26 17:27:24
【问题描述】:
我想要这样的视图,其中图像和文本并排,但它在图像下方显示文本:
[]
但它在图片在文本上方的位置显示为这样,我检查了我的代码,但我能够得到错误在哪里:
[]
我的hindu_design代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:elevation="10dp"
app:cardElevation="10dp"
app:cardMaxElevation="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/image"
android:scaleType="centerInside"
android:scaleX="0.5"
android:scaleY="0.9"
tools:srcCompat="@drawable/fruits" />
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:background="#00F85C2C"
android:gravity="center"
android:hapticFeedbackEnabled="false"
android:text="@string/todo"
android:textSize="20sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
我的 activity_hindu 代码:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="@drawable/background"
tools:context=".fragments.ShopFragment">
<LinearLayout
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/shop_heading"
android:layout_width="match_parent"
android:layout_height="77dp"
android:background="@drawable/headingbg"
android:fontFamily="@font/aclonica"
android:gravity="center"
android:text="@string/hindu"
android:textColor="@color/black"
android:textSize="24sp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:animateLayoutChanges="false"
tools:listitem="@layout/hindu_design" />
</LinearLayout>
</FrameLayout>
【问题讨论】:
-
您可以尝试不使用卡片视图吗?这是 LinearLayout 的一种奇怪行为。
-
你可以通过
NestedScrollView来实现
标签: android android-studio android-layout android-recyclerview android-cardview