【发布时间】:2025-12-04 21:40:01
【问题描述】:
这是我想要做的一个例子:
我尝试这样做的结果非常糟糕:
包含 CardView 和 ImageView 的 XML 代码,2 个 TextViews 和 ButtonImage:
这是我的 XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="@color/card"
app:cardCornerRadius="5dp"
app:cardElevation="6dp"
app:cardMaxElevation="10dp"
app:contentPadding="25dp">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/masarImg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="auto"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/masarTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/mapBtn"
android:layout_alignParentStart="true"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="43dp"
android:background="#AA000000"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="24dp"
android:text="SomeText"
android:textColor="#ffffffff"
android:textSize="24sp" />
<TextView
android:id="@+id/descreption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/mapBtn"
android:layout_alignParentStart="true"
android:layout_gravity="center_horizontal"
android:background="#AA000000"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="SomeText"
android:textColor="#ffffffff"
android:textSize="14sp" />
<ImageButton
android:id="@+id/mapBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:padding="8dp"
app:srcCompat="@drawable/b" />
</RelativeLayout>
</android.support.v7.widget.CardView>
您能帮我编写 XML 代码以获得漂亮的结果吗?
【问题讨论】:
标签: android android-layout user-interface android-imageview