TextView的自动水平滚动

TextView的自动水平滚动

本文介绍了在layout_weight TextView的自动水平滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找其他的线程,但我不能因此在这里找到答案我的问题是:

是否有可能创建一个按钮,它使用layout_weight权的自动水平滚动的TextView?

我在这里的超长搜索文本,按钮

我试图做一个滚动的TextView与FILL_PARENT,而不是0dp和layout_weight以及后来整个文本占据了行(很明显,因为它是FILL_PARENT)和按钮不会显示和文本没当我在Android虚拟设备跑了'吨水平滚动即使这样。

编辑:忘了写我如何设法使滚动的TextView

 <的TextView
 机器人:单线=真
 机器人:scrollHorizo​​ntally =真
 机器人:ellipsize =金字招牌
 机器人:marqueeRepeatLimit =marquee_forever
 机器人:layout_width =FILL_PARENT
 机器人:layout_height =WRAP_CONTENT
 机器人:ID =@ + ID / SearchResult中
 机器人:可聚焦=真
 机器人:focusableInTouchMode =真/>


解决方案

当然,这是可能的。像这样的东西会做什么:

 <的LinearLayout
    机器人:layout_widht =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:方向=横向>    <的TextView
        机器人:layout_width =0像素
        机器人:layout_weight =7
        ... />    <按钮
        机器人:layout_width =0像素
        机器人:layout_weight =3
        ... />< / LinearLayout中>

这里关键是使宽度为零,从而有剩余时的重量机构相对于它们的布局重分配所有剩余的空间来线性布局组件的所有水平空间。

I have been looking at other threads but I couldn't find an answer so here comes my question:

Is it possible to create a automatically horizontal scrolling TextView with a button to the right of it using layout_weight?

"My incredibly long search text here" "The button"

I have tried to make a scrollable textview with "fill_parent" instead of 0dp and layout_weight as well but then the entire text takes up the "row" (obviously since it is fill_parent) and the button is not shown AND the text didn't scroll horizontally even then when I ran it in the android virtual device.

Edit: forgot to write how I tried to make the scrollable textview

<TextView
 android:singleLine="true"
 android:scrollHorizontally="true"
 android:ellipsize="marquee"
 android:marqueeRepeatLimit="marquee_forever"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:id="@+id/searchResult"
 android:focusable="true"
 android:focusableInTouchMode="true"/>
解决方案

Of course it's possible. Something like this will do:

<LinearLayout
    android:layout_widht="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="0px"
        android:layout_weight="7"
        .../>

    <Button
        android:layout_width="0px"
        android:layout_weight="3"
        ... />

</LinearLayout>

Key here is make the width zero so that there's all horizontal space remaining when the weight mechanism assigns all remaining space to linear layout components in relation to their layout weight.

这篇关于在layout_weight TextView的自动水平滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 22:54