【问题标题】:how do I increase the cardView Size based on the text size?如何根据文本大小增加 cardView 大小?
【发布时间】:2016-06-17 21:52:54
【问题描述】:

如果我更改文本大小,它会溢出我的卡片视图如何更改卡片视图大小以适应当前的文本视图大小?

<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardview"
android:layout_width="match_parent"
android:layout_height="120dp"
card_view:cardElevation="1.5dp"
card_view:cardCornerRadius="0dp"
android:onClick="OnClick">

【问题讨论】:

  • 你能发布布局xml吗?你的卡片视图有固定大小吗?
  • 为什么不使用 wrap_content?如果你想有不同的大小,当你改变字体大小时,然后以编程方式改变卡片视图的大小。
  • 如果你想通过 textview 的文本大小来增加 cardview 的高度,使用 wrap_content 作为高度。
  • 就像其他人说的,使用 wrap_content。
  • 您可以将高度设置为其他人所说的包装内容并额外添加最小高度 120dp

标签: android android-studio text-size android-components


【解决方案1】:

如果你想改变卡片视图的大小而不是根据文本大小改变android:layout_height="wrap_content"

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/cardview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        card_view:cardCornerRadius="0dp"
        card_view:cardElevation="1.5dp">

EX :我试过了

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/cardview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        card_view:cardBackgroundColor="#85c7dc"
        card_view:cardCornerRadius="0dp"
        card_view:cardElevation="1.5dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:weightSum="2">

            <TextView
                android:id="@+id/txtDrVisit_DrName"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="ABC"
                android:textSize="25sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/txtDrVisit_DrDetails"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="ABC"
                android:textSize="45sp"
                android:textStyle="normal" />
        </LinearLayout>

    </android.support.v7.widget.CardView>
</LinearLayout>

【讨论】:

    猜你喜欢
    • 2022-01-08
    • 2012-11-23
    • 2015-02-15
    • 2014-11-09
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多