Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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"/>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
475 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...