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

すべてのボタンを1つのレイアウト(相対レイアウト)に保持し、このレイアウトをスクロールビュー内に保持するだけです。これで、レイアウト内のすべてのボタンがスクロールします。

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