2011-11-11 55 views
4

我有Horizo​​ntalScrollView包含水平线性布局时,我将新按钮添加到水平线性布局按钮添加在旁边的人从左到右,当超过屏幕的宽度新增加的按钮不会在屏幕上可见,但水平滚动将出现向右滚动
enter image description here
我想要从右向左而不是从左向右增加新按钮的方向为水平线性布局。
enter image description hereandroid horizo​​ntalScrollView布局组件的方向

+0

你怎么添加按钮?,你可以告诉我们的代码? –

回答

0

你可以当您使用简单地使用相对布局,并增加新的按钮,财产

android:layout_toLeftOf=""

2

实现这一目标:

myLinearLayout.addView(myButton); 

它增加了他们一个接一个。 但是如果你使用

myLinearLayout.addView(myButton, 0); 

它在LinearLayout中的第一个项目之前添加myButton

除了上面的代码,如果你想有你的Horizo​​ntalScrollView从右侧开始,你可以使用下面的代码:

new Handler().postDelayed(new Runnable() { 
    @Override 
    public void run() { 
     hScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT); 
    } 
}, 100L); 
+1

它很棒! –

1

我这样做。其作品API以上8:

<HorizontalScrollView 
     android:id="@+id/scrool" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:rotation="180" 
     android:fillViewport="true"> 

     <LinearLayout 
      android:id="@+id/lytAll" 
      android:layout_width="match_parent" 
      android:rotation="180" 
      android:layout_height="match_parent" 
      android:gravity="right" 
      android:orientation="horizontal"/> 

    </HorizontalScrollView>