【发布时间】:2019-12-31 08:58:00
【问题描述】:
我正在尝试在卡片视图右侧的布局中放置一个“新建”标签:
我在 Android Studio 中没有得到任何预览:显示布局但不显示内容可能是因为存在避免显示文本的约束。
你发现我的布局有什么错误吗?
代码:
<?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"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
app:cardElevation="2dp"
app:cardCornerRadius="4dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/img"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:contentDescription="@string/img_desc"
android:src="@mipmap/ic_launcher"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/img"
android:layout_centerVertical="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/cardview_head"
android:textSize="16sp"
android:textStyle="bold"
tools:text="test" />
<TextView
android:id="@+id/labelNew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/new_label"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:text="@string/new_label"
android:textColor="@color/white"
android:textSize="12sp"
tools:text="New" />
</LinearLayout>
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/cardview_subhead"
tools:text="test" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
【问题讨论】:
-
重量可以在班轮布局中管理重量
-
你在使用 Androidx 吗?
标签: android android-layout android-linearlayout android-relativelayout