Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement horizontal scroll for toolbar in android?

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

the scroll view is not working for the given layout. The commented code was written for horizontal scroll view. But its not working.

like image 708
Sayan Avatar asked Nov 05 '22 00:11

Sayan


1 Answers

in your xml file example.xml

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

in java code

LinearLayout standardtoolbar = (LinearLayout)findViewById(R.id.layout);
.
.
.
layout.addView(standardtoolbar, 0);
like image 120
MAC Avatar answered Nov 09 '22 11:11

MAC