Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HorizontalScrollView issue

I want to make a news ticker using a HorizontalScrollView. As a first step, I am simply trying out the HorizontalScrollView which contains only a Button as the content. I want the Button to fill the entire screen and the Button's text to be centered. But so far, the Button is stuck on the left side. Here is the code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<HorizontalScrollView
    android:layout_width="fill_parent"
    android:layout_height="40dip"
    android:layout_marginTop="50dip"
    android:background="#000000"
    android:scrollbars="none" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

        <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Button 1"
            android:textSize="20sp" />
    </LinearLayout>
</HorizontalScrollView>

How to solve this problem?

like image 246
user1107888 Avatar asked Dec 29 '25 14:12

user1107888


1 Answers

How to solve this problem?

Try to use the fillViewport attribute on the HorizontalScrollView:

android:fillViewport="true"
like image 199
user Avatar answered Dec 31 '25 04:12

user



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!