【问题标题】:android HorizontalScrollView layout component directionandroid Horizo​​ntalScrollView 布局组件方向
【发布时间】:2023-03-25 01:52:01
【问题描述】:

当我将新按钮添加到水平线性布局时,我的 Horizo​​ntalScrollView 包含水平线性布局,这些按钮从左到右彼此并排添加,当超出屏幕宽度时,新添加的按钮将在屏幕上不可见但水平滚动会出现向右滚动

我想将新按钮添加到水平线性布局的方向从右到左而不是从左到右。

【问题讨论】:

  • 你是如何添加按钮的?你能给我们看看代码吗?

标签: android android-linearlayout horizontalscrollview


【解决方案1】:

使用时:

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);

【讨论】:

    【解决方案2】:

    我这样做。它的工作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>
    

    【讨论】:

      【解决方案3】:

      您可以通过简单地使用相对布局并添加具有属性的新按钮来实现这一点

      android:layout_toLeftOf=""

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-31
        • 2011-10-18
        • 2014-02-13
        • 1970-01-01
        相关资源
        最近更新 更多