Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何将视图从右向左添加到水平滚动视图?_Android_Right To Left_Horizontalscrollview - Fatal编程技术网

Android 如何将视图从右向左添加到水平滚动视图?

Android 如何将视图从右向左添加到水平滚动视图?,android,right-to-left,horizontalscrollview,Android,Right To Left,Horizontalscrollview,我有一个内部带有线性布局的水平滚动视图,我在线性布局中添加了一些视图,这些视图是按钮!但问题是它们从左到右添加到线性布局中,我希望它们从右到左添加,我如何才能实现这一点 这是我的布局: <HorizontalScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/filteringSearchBox"

我有一个内部带有线性布局的水平滚动视图,我在线性布局中添加了一些视图,这些视图是按钮!但问题是它们从左到右添加到线性布局中,我希望它们从右到左添加,我如何才能实现这一点

这是我的布局:

<HorizontalScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/filteringSearchBox"
    android:layout_marginBottom="5dp"
    android:layout_marginTop="5dp"
    android:layoutDirection="rtl" >

    <LinearLayout
        android:id="@+id/filteringHeaderLL"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:gravity="end"
        android:layoutDirection="rtl"
        android:orientation="horizontal" >
    </LinearLayout>

</HorizontalScrollView>

我玩弄了布局方向和重力,它们都不起作用 请给我完整的答案

代码如下:

    for (int i = 0; i < mFilteringWB.length; i++) {
        Button mButton = new Button(mContext);
        mButton.setId(i);
        mButton.setTextColor(Color.parseColor("#6D6D6D"));
        mButton.setTextSize(13);
        mButton.setBackgroundResource(R.drawable.shad_filtering);
        mButton.setTypeface(mFace);
        mButton.setText(mFilteringWB[i]);
        mLayout.addView(mButton);
    }
for(int i=0;i
使用而不是


添加将这些按钮添加到scrollview的代码。@hasan83我添加了代码,编辑了我的问题,我想让按钮0位于最右侧的LinearYout中,这意味着我想从右到左开始布局顺序添加新视图后,您必须再次滚动到所需位置。应用程序就此崩溃,表示长度为6,计数=0@MahdiGiveie你在哪一行出错了?我想这和另一个有关thing@hasan83该行:mLayout.addView(mButton,1)@MahdiGiveie为什么是1?它必须为0,是否要在第一个位置“0”静态显示一些视图?mLayout.addView(mButton,0);非mLayout.addView(姆布顿,1);请重新测试。
mylinearLayout.add(myButton, 0); // add new views to index 0 which is left