安卓HorizontalScrollView布局组件方向

4
我有一个包含水平线性布局的HorizontalScrollView,当我添加新按钮到水平线性布局时,按钮会从左到右依次添加在一起,当超出屏幕宽度时,新添加的按钮将无法在屏幕上显示,但是会出现一个水平滚动条以向右滚动。
enter image description here
我想使添加新按钮到水平线性布局的方向从右到左而不是从左到右。
enter image description here

你是如何添加这些按钮的?能否给我们展示一下代码? - Yashwanth Kumar
3个回答

2

当你使用时:

myLinearLayout.addView(myButton);

它将它们一个接一个地添加。但是如果您使用

myLinearLayout.addView(myButton, 0);

这段代码在LinearLayout的第一个项目前添加了myButton

除了上面的代码,如果您希望您的HorizontalScrollView从右侧开始,可以使用以下代码:

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

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>

0

你可以通过使用相对布局并添加具有以下属性的新按钮来实现这一点:

android:layout_toLeftOf=""


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接