I’m busy with a horizontal scroll view with a single textview inside it.
I’m having trouble getting to get textview being able to slide from one side to the other without any space left.
If i just add the textview it’s not able to slide.
Basically all i want is a Horizontal scrollview with a textview in the center thats able to scroll either left or right but not overscroll (still visible)
eg: | Text | |Text | | Text| But not |ext | | Te|
My current layout looks like this:
<HorizontalScrollView
android:layout_width="250dp"
android:layout_height="35dp"
android:scrollbars="none" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="36dp" >
<Space
android:layout_width="125dp"
android:layout_height="wrap_content"
android:background="#808080" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST"
android:textSize="30dp" />
<Space
android:layout_width="125dp"
android:layout_height="wrap_content"
android:background="#808080" />
</LinearLayout>
</HorizontalScrollView>
I actually think that you have it mostly correct. I think however what you want to do is get the screen resolution at runtime, then with your textview that wraps content, get its runtime resolution, then make space left and space right’ width (at runtime) to (ScreenResWidth-TextViewWidth).
This means that you will want to give the TextView and both Spaces an ID so that you can access them from within your Java Code.
Use:
to center the text in your textview.
Use:
in your java code to get the post layout width (in pixels) of the textview.
Use:
to set your left and right space’ position and size using the top, left, right, and bottom parameters.
Give your Views IDs in your XML file using: