0

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"/>
jchiem
  • 3
  • 2
  • This question has already asked here. Take a look at [this](http://stackoverflow.com/a/3256305/2652124) – Renan Bandeira Aug 08 '13 at 10:04
  • tried it, didn't work, nothing is scrolling, I am not sure if you read the entire question or not. The question was if it is possible if there is another object like a button to the right of it using layout_weight anyway. – jchiem Aug 08 '13 at 10:13

1 Answers1

0

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.

laalto
  • 137,703
  • 64
  • 254
  • 280
  • So it is not possible basically, since what I want is a TextView with 0.7 in weight and a button with 0.3 in weight right next to it in the same LinearLayout ? One which can also automatically scroll the text horizontally – jchiem Aug 08 '13 at 14:34
  • @jchiem Of course it's possible and I've updated the answer to reflect this. – laalto Aug 09 '13 at 06:52
  • @laalto Can you post the full XML you used? Combining your XML with jchiem's XML does not result in scrolling text. –  Dec 09 '13 at 18:54
  • @dpk Cannot, sorry. I just quickly wrote up something to test this with and then threw it away. But as far as I remember, there wasn't anything special, just straightforward copy-pasting. – laalto Dec 09 '13 at 20:21