【问题标题】:Text vanishes and moves down on TextView because big size由于大尺寸,文本在 TextView 上消失并向下移动
【发布时间】:2014-03-20 18:26:38
【问题描述】:

对不起我的英语。我试图将我的文本保留在 TextView 上,但是当我设置大尺寸时他会向下移动。我已经设置了 android:gravity="center|left"。当尺寸小时没有问题。看起来不错。

text small size(抱歉我不能发图片)

不幸的是,如果我将大小设置为更大的文本会向下移动。

text big size

如果我再增加尺寸,文字也会消失。 1)如何防止文本移动? 2)如何防止文字消失?

我的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:padding="@dimen/fragmentDialogPad" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/textSizeET"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="number" >

    </EditText>

    <SeekBar
        android:id="@+id/textSizeSB"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="500" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center" >

        <Button
            android:id="@+id/buttonOka"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/okay" />

        <Button
            android:id="@+id/buttonCancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/cancel" />

    </LinearLayout>

</LinearLayout>

<TextView
    android:id="@+id/sampleTV"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:gravity="center|left"
    android:singleLine="true"
    android:includeFontPadding="false"
    android:text="Sample" />

</LinearLayout>

【问题讨论】:

  • 如果你能发布你的xml文件就好了..

标签: java android


【解决方案1】:

更改 layout_height 和 layout_width 以换行内容。如果这样做后问题仍然存在,则可能是我们的布局中没有足够的空间容纳您的 textview 。如果您发布您的xml,这将很有帮助。而且重力也应该是 android:gravity="center_vertical|left"。

我正在输入我的 xml 版本,它应该适合你

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    android:orientation="horizontal"
    android:weightSum="2"
    android:padding="0dp" >
    <LinearLayout
       android:layout_width="0dp"
       android:layout_height="wrap_content"
       android:layout_weight="1"
       android:orientation="vertical" >

<EditText
    android:id="@+id/textSizeET"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="number" >
</EditText>

<SeekBar
    android:id="@+id/textSizeSB"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:max="500" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/buttonOka"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="okay" />

    <Button
        android:id="@+id/buttonCancel"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:text="cancel" />
</LinearLayout>

 </LinearLayout>
 <LinearLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="center_vertical|left"
    android:layout_gravity="center_vertical"
    android:orientation="vertical" >
    <TextView
      android:id="@+id/sampleTV"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textSize="150dp"
      android:singleLine="true"
      android:includeFontPadding="false"
      android:text="Sample" />
     </LinearLayout>
   </LinearLayout>

【讨论】:

  • android:gravity="center_vertical|left" 没有帮助 :(。请参阅我的 xml 文件。
  • @Argamidon 我认为您的 fragmentDialogPad 可能很高。尝试减少它。我也无法访问您发布的屏幕截图。如果您的内容对屏幕来说太多,您应该考虑使用 scollview。
  • 我刚刚更新了图片链接。 @dimen/fragmentDialogPad 是 0dp。
  • @Argamidon 我刚刚更新了我的答案。请检查这是否适合您。
  • 我尝试了很多组合,但它不起作用,我有足够的。谢谢你的帮助。我将按原样使用它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-02
  • 2020-02-15
  • 1970-01-01
  • 2022-01-04
  • 1970-01-01
相关资源
最近更新 更多