How do I add a custom view to a HorizontalScrollView?
So, I followed a tutorial for drawing stuff on android. I have created a Panel class that extends SurfaceView that I draw on using a th开发者_开发问答read. Now I want to put this Panel in a scroll view, specifically one that scrolls horizontally so that I can draw stuff wider than the screen. I would I go about doing that?
this can be done in the XML of the project what you want to do is, whatever you want to be int the scrollview, you put inside a scrollview in xml. it would be in between:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
and:
</ScrollView>
Imagine that your custom component is named (the class) MyCustomComponent and the package it's in is org.neteinstein.code
The xml would be:
<HorizontalScrollView android:id="@+id/scroll" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:fillViewport="true">
<org.neteinstein.code.MyCustomComponent android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</HorizontalScrollView >
精彩评论