如何在android中实现工具栏的水平滚动?

如何在android中实现工具栏的水平滚动?,android,scrollview,Android,Scrollview,滚动视图不适用于给定布局。注释代码是为水平滚动视图编写的。但是它不起作用。在您的xml文件example.xml中 LinearLayout standardtoolbar = new LinearLayout(context); standardtoolbar.setMinimumWidth(10); standardtoolbar.setMinimumHeight(50); Bitmap toolbarBackgroundIma

滚动视图不适用于给定布局。注释代码是为水平滚动视图编写的。但是它不起作用。

在您的xml文件example.xml中

        LinearLayout standardtoolbar = new LinearLayout(context);
        standardtoolbar.setMinimumWidth(10);
        standardtoolbar.setMinimumHeight(50);
        Bitmap toolbarBackgroundImage = SkinManager.getInstance().getImageBitmap("BarBackground");
        Drawable d = new BitmapDrawable(toolbarBackgroundImage);
        standardtoolbar.setBackgroundDrawable(d);
        RelativeLayout.LayoutParams lpstandardtool = new RelativeLayout.LayoutParams(5, LayoutParams.WRAP_CONTENT);
        lpstandardtool.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        toolbarLayout.addView(standardtoolbar, 0);
        /*toolbarLayout.getScrollX();
        toolbarLayout.scrollBy(5, 0);
        toolbarLayout.setScrollBarStyle(0);
        */    
        ScrollView scroll = new ScrollView(AppController.getInstance().getCurrentActivity());
        scroll.addView(toolbarLayout);
工具栏布局..设置方向(LinearLayout.HORIZONTAL);
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="wrap_content>  

   <LinearLayout android:id="layout" android:layout_height="wrap_content" android:layout_width="wrap_content" android:orientation="horizontal">

   </LinearLayout>
</HorizontalScrollView>
LinearLayout standardtoolbar = (LinearLayout)findViewById(R.id.layout);
.
.
.
layout.addView(standardtoolbar, 0);