当前位置: 首页 > 知识库问答 >
问题:

TextView在某些解决方案中被剪切

巩阳秋
2023-03-14

我有一个recyclerView,它由CardView组成,其中有一个TextView和一个ImageView以及一些其他布局。
问题是,在某些屏幕分辨率中,TextView会被切断或被推到下一行,这是我不想要的。
在其他分辨率中,TextView有很多空间。

如何组织布局,使TextView有足够的空间,并相应地调整ImageView的大小?

这是RecyclerView项的xml:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
android:id="@+id/zmanCard"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
cardview:cardUseCompatPadding="false"
cardview:cardPreventCornerOverlap="false"
cardview:cardCornerRadius="4dp"
cardview:cardElevation="2dp">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?attr/colorPrimary"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:layout_gravity="top"
        android:gravity="center"
        android:orientation="vertical"
        android:background="?attr/colorPrimaryDark">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/zmanCardTitle"
            android:textColor="#ffffff"
            android:gravity="center"
            android:textSize="13sp" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <ImageView
            android:layout_width="24dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="4dp"
            android:alpha="0.8"
            android:id="@+id/zmanCardImage" />
        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="7dp"
            android:layout_marginLeft="0dp"
            android:layout_marginRight="4dp">
            <TextView
                android:text="5:40"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="2dp"
                android:id="@+id/zmanCardTime"
                android:textColor="#ffffff"
                android:textSize="18sp" />
            <ProgressBar
                android:id="@+id/zmanProgressBar"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_gravity="top|left"
                style="@style/Base.Widget.AppCompat.ProgressBar" />
        </FrameLayout>
    </LinearLayout>
</LinearLayout>

共有1个答案

魏浩广
2023-03-14

试试这个。百分百有效。

AutoResizeTextView或sdp单元可以帮助您。

SDP-一个可伸缩的单元

一个android SDK,它提供了一个新的大小单元--sdp(可伸缩dp)。此大小单位随屏幕大小而缩放。它可以帮助Android开发者支持多屏。

关于文本视图,请参考ssp,它基于文本的sp大小单位。

https://github.com/intuit/sdp

自动缩放TextView文本以适应边界

如果您希望支持不同屏幕的不同布局设计:

res/layout/my_layout.xml             // layout for normal screen size ("default")
res/layout-small/my_layout.xml       // layout for small screen size
res/layout-large/my_layout.xml       // layout for large screen size
res/layout-xlarge/my_layout.xml      // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

欲了解更多信息请参阅此处

 类似资料:
  • 因此,我正在使用很棒的MPAndroid图表库来制作一个简单的LineChart。我能够使用GitHub上的示例项目大量定制它。 问题是,当我将它移到我自己的代码中时,某些方法不再能够解决: 特别是mlineChart.setExtraOffsets()和mlineChart.setAutoScaleminMaxEnabled()。可能还有其他的,但这是我注意到的仅有的两个。 不过,其他一切都很好

  • 1px 方案在 VUX 组件内应用广泛,包括 Grid, ButtonTab, XTable, XButton, Cell 等等。 利用 Flexbox + 1px 你可以实现复杂的宫格布局。 引入 在你项目的App.vue引入,组件内不需要再重复引入。 <style lang="less"> @import '~vux/src/styles/1px.less'; </style> 可用类名:

  • 本文向大家介绍innerHTML在IE中报错解决方案,包括了innerHTML在IE中报错解决方案的使用技巧和注意事项,需要的朋友参考一下 问题:开发过程中,用到循环往table里面插入tr标签,然后tr里又循环插入td,在其它浏览器都没问题,但是在IE9及以下版本中都报错: google上得到答案:由于我之前不知道错误的原因,在百度找不到解决方法,后来用谷歌搜到了,外国有人也遇到过这个问题,并指

  • 我写了一个相当基本的js函数,它以编程方式自动将iPhone键盘完美地对准每一个聚焦的输入字段(如果你喜欢,可以随意使用它!)。对齐主要由window.scroll处理——这是一种标准方法,适用于任何浏览器视图,UIWebView除外,因此是phonegap/cordova(2.1)。所以我需要一个变通方法。 我的工作代码: 工作在一切,但UIWebView,这是。正如我上面提到的,除了windo

  • 你可以看到,虽然我们有一些复制对象的方法,但是我们没有使它不可变,因为我们可以将episode的属性设置为8.另外,在这种情况下我们如何修改episode属性? 我们通过调用assign: name: 'Star Wars', console.log(movie1.episode); // writes 7