I have 5 buttons i want to scroll them all the buutons,my code is
<Button android:id="@+id/btnAll" android:layout_height="wrap_content" android:layout_width="80dip" android:text="All" android:background="@drawable/green1" /> <Button android:id="@+id/btnBarAndRes" android:layout_height="wrap_content" android:layout_width="80dip" android:text="Bar Restaurants" android:layout_t开发者_运维知识库oRightOf="@+id/btnAll" android:background="@drawable/green1" /> <Button android:id="@+id/btnFashion" android:layout_height="wrap_content" android:layout_width="80dip" android:text="FashionBeauty" android:layout_toRightOf="@+id/btnBarAndRes" android:background="@drawable/green1"/> <Button android:id="@+id/btnParty" android:layout_height="wrap_content" android:layout_width="80dip" android:text="PartyEntertainment" android:layout_toRightOf="@+id/btnFashion" android:background="@drawable/green1" /> <Button android:id="@+id/btnLife" android:layout_height="wrap_content" android:layout_width="80dip" android:text="Life Style" android:layout_toRightOf="@+id/btnParty" android:background="@drawable/green1" /> </RelativeLayout> </ScrollView> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:id="@+id/linearLayout1"
android:orientation="horizontal"
android:layout_height="fill_parent">
<Button
android:id="@+id/btnAll"
android:layout_height="wrap_content"
android:layout_width="80dip"
android:text="All"
android:background="@drawable/icon" />
<Button
android:id="@+id/btnBarAndRes"
android:layout_height="wrap_content"
android:layout_width="80dip"
android:text="Bar Restaurants"
android:layout_toRightOf="@+id/btnAll"
android:background="@drawable/icon" />
<Button
android:id="@+id/btnFashion"
android:layout_height="wrap_content"
android:layout_width="80dip"
android:text="FashionBeauty"
android:layout_toRightOf="@+id/btnBarAndRes"
android:background="@drawable/icon"/>
<Button
android:id="@+id/btnParty"
android:layout_height="wrap_content"
android:layout_width="80dip"
android:text="PartyEntertainment"
android:layout_toRightOf="@+id/btnFashion"
android:background="@drawable/icon"
/>
<Button
android:id="@+id/btnLife"
android:layout_height="wrap_content"
android:layout_width="80dip"
android:text="Life Style"
android:layout_toRightOf="@+id/btnParty"
android:background="@drawable/icon"
/>
</LinearLayout>
</HorizontalScrollView>
</ScrollView>
you just keep all the buttons in one layout(Relative layout) and keep this layout within scrollview. now all the buttons within layout will scroll.
<RelativeLayout>
<ScrollView>
<RelativeLayout>
<Button>
//Place code for button1
</Button>
<Button>
//Place code for button2
</Button>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
精彩评论