【发布时间】:2020-09-11 07:25:51
【问题描述】:
在 Android L 的 CardView 中使用时,某些视图不会包装其内容。在早期版本的 Android 上测试相同的代码时,一切正常。这是我的布局:
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/stock_row_height"
card_view:cardCornerRadius="@dimen/default_elevation"
card_view:cardElevation="@dimen/default_elevation"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/logo"
android:layout_width="@dimen/portals_logo_width"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_margin="@dimen/portals_logo_margin"
android:adjustViewBounds="true"
android:src="@drawable/image_placeholder" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/logo"
android:layout_toRightOf="@+id/logo"
android:background="@android:color/black"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_green_light"
android:text="portalAddress.com"
android:textColor="@android:color/black"
android:textSize="@dimen/portals_title_text_size" />
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_light"
android:text="Sincronizado 04/12/14 às 14:25"
android:textColor="@color/medium_gray"
android:textSize="@dimen/portals_description_text_size" />
</LinearLayout>
</RelativeLayout>
问题是高度的 TextView "wrap_content" 不起作用。这是来自 Android Studio 的预览可视化:
这是在搭载 Android L 的三星 Galaxy S5 上运行的相同布局:
Samsung Galaxy S5 with Android L
如果我尝试为两个 TextView(分别为 25dp 和 18dp)设置固定高度,则父 LinearLayout 不会以与 TextView 相同的方式包装其内容。
[TextView 的固定高度][3]
我错过了什么?不知道是什么问题,因为这只发生在 Android L 中。
编辑:我仍在寻找解决此问题的方法。
【问题讨论】:
-
我没有足够的声望来发布 3 个链接,所以这里是最后一个的地址 - Fixed height for TextView
-
您找到解决方案了吗?我也有同样的问题。
标签: android android-layout textview android-cardview