TextView在某些分辨率下被削减 [英] TextView getting cut in some resolutions

查看:60
本文介绍了TextView在某些分辨率下被削减的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RecyclerView,它由具有TextViewImageViewCardView组成,以及其他一些布局.
问题是,在某些屏幕分辨率下,TextView会被截断或推到下一行,这是我不希望的.
在其他分辨率中,TextView有足够的空间.

I have a RecyclerView which consists of CardViews that have a TextView and an ImageView, among some other layouts.
The problem is, in some screen resolutions the TextView gets cut off or shoved to the next line, which I don't want.
In other resolutions, the TextView has plenty of room.

小分辨率:

Small Resolutions:

高分辨率:

High Resolutions:

如何组织布局,以便为TextView提供足够的空间,并且ImageView的大小将相应调整?

How do I organize the layout so that there is enough room for the TextView, and the ImageView will be sized accordingly?

这是我的RecyclerView项目的xml:

This is my xml for the RecyclerView items:

<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>

推荐答案

尝试一下.运作100%.

Try this. Works 100%.

> AutoResizeTextView sdp 单元可以为您提供帮助.

AutoResizeTextView or sdp unit can help you.

SDP -可扩展的尺寸单位

SDP - a scalable size unit

提供新尺寸单位的android SDK- sdp ( 可扩展的dp ).此大小单位与屏幕大小成比例.它可以帮助Android开发人员支持多个屏幕.

An android SDK that provides a new size unit - sdp (scalable dp). This size unit scales with the screen size. It can help Android developers with supporting multiple screens.

有关文本视图,请参阅基于sp大小单位的ssp.

for text views please refer to ssp which is based on the sp size unit for texts.

https://github.com/intuit/sdp

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

如果要为不同的屏幕支持不同的布局设计:

And if you want support different layout designs for different screen:

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

有关更多信息,请参见此处

Fore more information look here

这篇关于TextView在某些分辨率下被削减的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆