1

我有 5 个按钮我想滚动它们所有的按钮,我的代码是

                    <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_toRightOf="@+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>
4

2 回答 2

3
<?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>
于 2011-08-01T06:29:19.813 回答
0

您只需将所有按钮保留在一个布局中(相对布局)并将此布局保留在滚动视图中。现在布局中的所有按钮都会滚动。

<RelativeLayout>
<ScrollView>
 <RelativeLayout>
   <Button>
        //Place code for button1
    </Button> 
     <Button>
        //Place code for button2
    </Button> 
  </RelativeLayout>
</ScrollView>
</RelativeLayout>
于 2011-07-31T06:33:48.540 回答