【问题标题】:android HorizontalScrollView layout component directionandroid HorizontalScrollView 布局组件方向
【发布时间】:2023-03-25 01:52:01
【问题描述】:
当我将新按钮添加到水平线性布局时,我的 HorizontalScrollView 包含水平线性布局,这些按钮从左到右彼此并排添加,当超出屏幕宽度时,新添加的按钮将在屏幕上不可见但水平滚动会出现向右滚动
我想将新按钮添加到水平线性布局的方向从右到左而不是从左到右。
【问题讨论】:
标签:
android
android-linearlayout
horizontalscrollview
【解决方案1】:
使用时:
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);
【解决方案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=""