【问题标题】:Android font out of view on small screenAndroid字体在小屏幕上看不到
【发布时间】:2011-06-29 02:24:42
【问题描述】:

我有几个文本视图,它们在相对布局的横向视图中占据了屏幕的大部分,并且我设置的字体大小非常大(150dp)。文本视图都是计时器,最右边的是“秒”文本视图。

我的问题是,在具有小屏幕分辨率的手机上进行测试时,秒数超出了屏幕的限制,无法看到。它们在普通到大屏幕分辨率上处于完美的位置,而不是在小屏幕上。

有什么方法可以强制“秒”文本视图留在屏幕上,而无需调整每个文本视图之间的字体大小或边距?即使这意味着在小屏幕上看起来局促,我也可以忍受。

非常感谢任何帮助。

谢谢

这是包含小时和分钟文本视图的相对布局和线性布局的相应代码

<?xml version="1.0" encoding="utf-8"?>
      <RelativeLayout android:id="@+id/RelativeLayout01"
       android:layout_width="fill_parent" android:layout_height="fill_parent"
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:keepScreenOn="true" android:background="@drawable/background2">


<RelativeLayout android:id="@+id/RelativeLayout08"

android:paddingLeft="20dip" android:paddingRight="30dip"
android:background="@drawable/trans_img" android:layout_centerHorizontal="true" 
android:paddingBottom="20dip" android:layout_centerVertical="true" 
android:layout_height="wrap_content" android:layout_width="wrap_content">

<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_centerVertical="true">

<TextView android:id="@+id/TextViewHr1" 
android:layout_width="wrap_content" android:layout_height="wrap_content" 
android:layout_marginRight="5dip" android:gravity="right" 
android:textColor="@color/white" android:textSize="150dp" 
android:layout_marginLeft="5dip"></TextView>

<TextView android:id="@+id/TextViewHr2" 
android:layout_width="wrap_content" android:layout_height="wrap_content" 
android:layout_marginLeft="5dip" android:layout_marginRight="5dip" 
android:gravity="right" android:textColor="@color/white" 
android:textSize="150dp"></TextView>

<TextView android:id="@+id/TextViewSeperate" 
android:layout_width="wrap_content" android:layout_marginLeft="5dip" 
android:layout_marginRight="5dip" android:layout_gravity="center_vertical" 
android:background="@drawable/colon" android:layout_height="55dip"></TextView>

<TextView android:id="@+id/TextViewMin1" 
android:layout_width="wrap_content" android:layout_height="wrap_content" 
android:layout_marginLeft="5dip" android:layout_marginRight="5dip" 
android:gravity="right" android:textColor="@color/white" 
android:textSize="150dp"></TextView>

<TextView android:id="@+id/TextViewMin2" 
android:layout_height="wrap_content" android:layout_marginLeft="5dip"
android:gravity="right" android:layout_width="wrap_content" 
android:textColor="@color/white" android:textSize="150dp" 
android:layout_marginRight="5dip"></TextView
</LinearLayout>

这是第二个线性布局的代码,在这个相对布局 8 中:

<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="wrap_content" android:layout_height="wrap_content" 
android:orientation="vertical" android:layout_centerVertical="true"
android:layout_toRightOf="@+id/LinearLayout01" android:layout_marginLeft="20dip">

<TextView android:id="@+id/TextViewSeconds" 
android:layout_height="wrap_content" android:text="20" 
android:layout_marginTop="5dip" android:textColor="@color/white" 
android:textSize="55dip" android:layout_width="wrap_content"></TextView>

【问题讨论】:

    标签: android textview font-size screen-size


    【解决方案1】:

    我会尝试设置 layout_weight 设置。

    要做到这一点,请尝试以下操作: 在父 weight_sum = "1.0"

    中设置

    在子百分比值中,他们需要占用多少空间即layout_weight="0.8"layout_weight="0.2",记得设置layout_width = "0dp" 在父级的所有元素中。

    【讨论】:

    • 谢谢 这是否意味着为包含所有文本视图的相对布局设置 weight_sum = 1.0,然后为被切断的“秒”文本视图设置 weight = 0.2?另外,如果我将相对布局宽度设置为 0dp,那不会搞砸吗?因为有它的背景再次感谢
    • 不会乱的。如果我们使用 layout_weight 视图绘制以适应屏幕的百分比值,那么在 0.8 中它是屏幕上 80% 的位置。这就是你应该如何处理不同屏幕尺寸的问题。
    • 我尝试了这种方法,但由于某种原因无法使其正常工作。所以我有一个相对布局,然后包含两个线性布局。第一个线性布局包含小时和分钟文本视图,第二个包含秒文本视图。我将 android:weightSum="1.0" 应用于相对布局,然后对于线性布局 1(包含小时和分钟)我设置 android:layout_weight="0.8" 和线性布局 2(秒)我应用 android:layout_weight="0.2" .我为两个线性布局设置了 layout_width="0dp" 。我感谢任何澄清谢谢
    • 这个元素的过去代码,我来测试一下。现在我看不出问题出在哪里。
    • 谢谢,我已经用代码编辑了我上面的帖子。我没有添加上面的权重元素,因此您可以在没有它们的情况下查看代码。再次感谢
    猜你喜欢
    • 1970-01-01
    • 2020-07-18
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 2020-09-20
    • 1970-01-01
    • 2020-12-28
    • 1970-01-01
    相关资源
    最近更新 更多