1

enter image description here

My question is i have a View and seekbar.now i want to control the height of the View with the help of a SeekBar..i.e the View height increases when the SeekBar is dragged towards right and decreases while dragging towards left...what i want it, i have explain in example image..

when i dragged seekbar towards right,the View height is increase.and when i dragged seekbar towards left,the View height is decrease..any help will be much appreciated..Thanks Alot in advance.

Farhan Shah
  • 2,344
  • 7
  • 28
  • 54

1 Answers1

2

I have implemented demo.Adjust height as per your requirement.I hope you will get some idea.

MainActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.seekbar_layout);

    ((SeekBar)findViewById(R.id.sbHeight)).setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {

            if(progress > 0 && progress < 30)
                progress = 40;
            else if(progress > 30 && progress < 60)
                progress = 60;
            else if(progress > 60 && progress < 100)
                progress = 80;

            if(progress != 0)
                setViewHeight(progress);                
        }
    });

    ((LinearLayout)findViewById(R.id.llHeight)).setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,60));        
}

private void setViewHeight(int progress)
{
    ((LinearLayout)findViewById(R.id.llHeight)).setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,progress));
}

seekbar_layout.xml

 <RelativeLayout 
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical" 
   >
    <LinearLayout 
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="vertical" 
       android:gravity="center"
       android:layout_marginTop="20dp"
       >
        <LinearLayout 
           android:id="@+id/llHeight"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:orientation="vertical" 
           android:background="#3296ed"
           >
        </LinearLayout>
    </LinearLayout>

    <SeekBar 
        android:id="@+id/sbHeight"
        android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:progress="50"
    android:layout_marginBottom="140dp"
    android:layout_alignParentBottom="true"
    />
 </RelativeLayout>
VJ Vélan Solutions
  • 6,434
  • 5
  • 49
  • 63
TheFlash
  • 5,997
  • 4
  • 41
  • 46