繁体   English   中英

Android应用程序:文本在较小的设备上被裁剪

[英]Android app: text getting cropped on smaller devices

我们正在开发一个android应用。 文本在5英寸设备上正确显示。但是在较小的设备(4英寸,3.5英寸)上被裁剪。为什么会出现这种情况?欢迎任何帮助。请参见下面的屏幕快照。显示“贷方”,“借方”和“净额”,而不是下面的屏幕快照中的“信用卡”,“借记卡”和“网上银行”。

在更大的设备上

在较小的设备上

<?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:orientation="vertical" 
    android:background="#ffffff" >
    <include android:layout_width="match_parent"
              android:layout_height="wrap_content"
              layout="@layout/sdk_header"
              />

 <RelativeLayout 
     android:id="@+id/topLogoLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"
      android:layout_marginTop="0dp" 
      android:layout_marginRight="0dp" 
      android:layout_marginLeft="0dp" 
      android:layout_marginBottom="-11dp" 
      android:background="#e5e5e5" 
      android:paddingTop="10dp" 
      android:paddingBottom="20dp">

  <TextView 
      android:id="@+id/youtxt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:gravity="right" 
      android:layout_marginTop="5dp"
      android:text="You"
 android:textSize="40sp" 
 android:textColor="#727272" 
 android:layout_marginLeft="10dp" /> 

 <RelativeLayout 
     android:id="@+id/arrowLayout" 
     android:layout_toRightOf="@+id/youtxt"
     android:layout_toLeftOf="@+id/companyLogo"
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"
     android:layout_marginTop="5dp"
     android:layout_centerHorizontal="true">

  <TextView 
      android:id="@+id/txt_amount" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:text="Rs. 10" 
      android:textColor="#727272" 
      android:textSize="18sp" /> 

   <ImageView 
      android:id="@+id/arrow" 
      android:layout_width="wrap_content" 
      android:layout_height="18dp" 
      android:src="@drawable/arrow" 
      android:layout_below="@+id/txt_amount" /> 

  </RelativeLayout>

  <ImageView 
      android:id="@+id/companyLogo" 
      android:layout_marginTop="5dp" 
      android:layout_marginRight="30dp" 
      android:layout_width="70dp" 
      android:layout_height="50dp" 
      android:layout_alignParentRight="true" 
      android:src="@drawable/wallet_logo" 
      android:scaleType="fitXY" /> 
  </RelativeLayout>

  <ImageView 
      android:id="@+id/orange_line"  
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:src="@drawable/orange_line" 
      /> 
  <com.viewpagerindicator.TabPageIndicator 
      android:layout_marginTop="0dp"
      android:id="@+id/indicator" android:layout_height="wrap_content" android:layout_width="fill_parent" /> 
  <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="wrap_content" android:layout_height="wrap_content" >



  </android.support.v4.view.ViewPager> 

</LinearLayout>

这是一个很复杂的主题,可以在上面写一本书(也许有)。 我将集中讨论我能看到的唯一问题:文本大小。

在小屏幕上,您的字体似乎太大了。 尽管EditText也有问题(只是不会溢出),但这会影响选项卡和按钮的外观。

测量屏幕尺寸的有用方法是sw-dp(最短宽度的设备独立像素)。 调整dp密度,以便在所有设备上都达到160dpi左右。 对于宽度为3英寸的5英寸平板电脑,应为sw480dp设备。 3“ -3.5”屏幕的宽度约为2“,应为sw320dp设备。

为了使此工作最简单,您需要在value-sw240dp文件夹中放置一些文本大小设置,这些设置大约是默认sw480dp设备的文本大小的3/4。

例如,这可能会出现在该文件夹的dimen文件中。

<dimen name="view_field_text_size">14sp</dimen>

我无法提供食谱,因为我没有有关您使用样式或尺寸的其他信息。 也许在布局中您可能具有:

<EditText
   <android:textSize="@dimen/view_field_text_size"
/>

最好采用一种样式,但这超出了此处的范围。

不同的设备可能具有不同的像素密度,屏幕尺寸,方向,分辨率和与密度无关的像素(dp)

解决方案 -

  • 为不同的屏幕尺寸定义不同的布局文件。
  • 确保可以适当调整布局大小以适合屏幕
  • 根据屏幕配置提供适当的UI布局
  • 确保将正确的布局应用于正确的屏幕

默认情况下,Android会调整应用程序布局的大小以适合当前设备屏幕。 在大多数情况下,这可以正常工作。 在其他情况下,您的UI可能看起来不那么好,可能需要针对不同的屏幕尺寸进行调整。 例如,在较大的屏幕上,您可能需要调整某些元素的位置和大小以利用额外的屏幕空间,或者在较小的屏幕上,可能需要调整大小以使所有内容都适合屏幕。

可用于提供特定于大小的资源的配置限定符为small,normal,large和xlarge。 例如,超大屏幕的布局应放在layout-xlarge /中。

从Android 3.2(API级别13)开始,不建议使用上述大小组,而应使用swdp配置限定符定义布局资源所需的最小可用宽度。 例如,如果您的多窗格平板电脑布局需要至少600dp的屏幕宽度,则应将其放置在layout-sw600dp /中。 关于声明Android 3.2平板电脑布局的部分中,将进一步讨论使用新技术声明布局资源。

外观- 多屏支持支持屏培训文档

您只需要创建与密度或屏幕尺寸相关的其他文件夹,例如

选项1。

values-large
values-small
values-normal

有关更多说明,请检查此链接...

多屏支持

选项2。

mTextView.setTextSize(16 * getResources().getDisplayMetrics().density);

这将根据密度提供TextSize。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM