android - How to make a Horizontal ScrollView -
i want scroll horizontally when run code of buttons in first relativelayout out of screen , not scroll see them. google store have blocks , each block can scrolled horizontally see more
my xml :
<scrollview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:scrollbars="horizontal|vertical" tools:context=".mainactivity" > <tablelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <relativelayout android:layout_width="626dp" android:layout_height="wrap_content" > <button android:id="@+id/button1" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="button" /> <button android:id="@+id/button2" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_aligntop="@+id/button1" android:layout_torightof="@+id/button1" android:text="11:00" /> <button android:id="@+id/button3" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_torightof="@+id/button2" android:text="14:30" /> <button android:id="@+id/button4" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_torightof="@+id/button3" android:text="14:30" /> <button android:id="@+id/button5" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_torightof="@+id/button4" android:text="14:30" /> <button android:id="@+id/button6" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_torightof="@+id/button5" android:text="14:30" /> <button android:id="@+id/button7" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_torightof="@+id/button6" android:text="14:30" /> </relativelayout> <relativelayout > <button android:id="@+id/button8" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:layout_marginleft="16dp" android:text="button" /> <button android:id="@+id/button9" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:text="button" /> </relativelayout> </tablelayout> </scrollview>
you need use horizontalscrollview
instead of scrollview
. try this:
<horizontalscrollview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:scrollbars="horizontal|vertical" tools:context=".mainactivity" > <!-- set width wrap_content of first child view horizontalscrollview --> <tablelayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="horizontal" > <relativelayout android:layout_width="626dp" android:layout_height="wrap_content" > <button android:id="@+id/button1" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="button" /> <button android:id="@+id/button2" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_aligntop="@+id/button1" android:layout_torightof="@+id/button1" android:text="11:00" /> <button android:id="@+id/button3" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_torightof="@+id/button2" android:text="14:30" /> <button android:id="@+id/button4" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_torightof="@+id/button3" android:text="14:30" /> <button android:id="@+id/button5" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_torightof="@+id/button4" android:text="14:30" /> <button android:id="@+id/button6" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_torightof="@+id/button5" android:text="14:30" /> <button android:id="@+id/button7" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_torightof="@+id/button6" android:text="14:30" /> </relativelayout> <relativelayout > <button android:id="@+id/button8" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:layout_marginleft="16dp" android:text="button" /> <button android:id="@+id/button9" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:text="button" /> </relativelayout> </tablelayout> </horizontalscrollview>
Comments
Post a Comment