TextView的大小和滚动的问题(Android版) [英] TextView size and scrolling issue (Android)

查看:156
本文介绍了TextView的大小和滚动的问题(Android版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是有一个滚动型TextView中可以包含不同的文本。文本的大小总是不同。问题是,在不同屏幕上这个TextView的可完全放置在屏幕或没有。我想垂直居中文字在屏幕上。如果文字是小,它工作正常。但是,如果文本长度大于一屏可显示的,它只是失去了文本的开头,也显示的文本后,奇怪的空白区域。我该如何解决这个问题?

属性重力的TextView只是居中文字水平,但 layout_gravity 那奇怪的事情上面描述我。如果我删除 layout_gravity ,所有的文字看起来不错,但它在滚动视图顶部=(

 <滚动型
    机器人:layout_width =match_parent
    机器人:layout_height =0dp
    机器人:layout_above =@ ID / llbuttons
    机器人:layout_alignParentTop =真
    机器人:layout_margin =15dp>    <的TextView
        机器人:ID =@ + ID / TextView的
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:比重=中心
        机器人:layout_gravity =center_vertical
        机器人:TEXTSIZE =36sp
        机器人:文字样式=大胆/>
< /滚动型>


解决方案

有没有必要滚动型,你需要在XML中添加2个属性机器人:MAXLINES 的android:滚动条=垂直

XML

 <的TextView
        机器人:ID =@ + ID / babySitterDescTxtView
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_marginTop =18dp
        机器人:MAXLINES =3
        机器人:paddingLeft =50dp
        机器人:paddingRight =50dp
        机器人:滚动条=垂直
        机器人:文字=Lorem存有是印刷排版行业的简单虚拟文本Lorem存有一直是业界和放大器;氏标准的虚拟文本,自从16世纪。
        机器人:文字颜色=@彩色/ fragment_page_txt_color
        机器人:字体=SANS/>

JAVA

  babySitterDescTxtView =(的TextView)findViewById(R.id.babySitterDescTxtView);
babySitterDescTxtView.setMovementMethod(新ScrollingMovementMethod());

I just have a TextView in a ScrollView which can contain different text. The size of the text is always different too. The problem is that on different screens this TextView can be fully placed on screen or not. I want to center the text vertically on screen. If the text is small, it works fine. But if the text length is bigger than the screen can contain, it just loses the beginning of text and also the strange empty space after text appears. How can I fix this?

The attribute gravity of textview just centers the text horizontally, but layout_gravity does that strange thing I described above. If I remove layout_gravity, all the text looks good, but it's at the top of the scrollview =(

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_above="@id/llbuttons"
    android:layout_alignParentTop="true"
    android:layout_margin="15dp" >

    <TextView
        android:id="@+id/textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_gravity="center_vertical"
        android:textSize="36sp"
        android:textStyle="bold" />
</ScrollView>

解决方案

There is no need of ScrollView you need to add 2 attributes in xml android:maxLines and android:scrollbars="vertical"

XML

<TextView
        android:id="@+id/babySitterDescTxtView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="18dp"
        android:maxLines="3"
        android:paddingLeft="50dp"
        android:paddingRight="50dp"
        android:scrollbars="vertical"
        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&apos;s standard dummy text ever since the 1500s."
        android:textColor="@color/fragment_page_txt_color"
        android:typeface="sans" />

in JAVA

babySitterDescTxtView = (TextView) findViewById(R.id.babySitterDescTxtView);
babySitterDescTxtView.setMovementMethod(new ScrollingMovementMethod());

这篇关于TextView的大小和滚动的问题(Android版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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