Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8584491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:47:10+00:00 2026-06-11T21:47:10+00:00

I’m dynamically modifying height of the button based on seekbar progress. Now I want

  • 0

I’m dynamically modifying height of the button based on seekbar progress.

Now I want to retreive height of the button. So I used btn1.getHeight() in onProgressChanged() method of SeekBar.
But it gives incorrect/old set of values for button height.

Instead, if I used btn1.getHeight() in onStopTrackingTouch(), I’m getting correct values.

This simply means , when I try to retreive height of the button in onProgressChanged() , UI changes are visible on screen but yet not registered wchich results into getting incorrect/old values.

How to get correct values in onProgressChanged() ?

Is there other way round to do this? Any help appreciated.

Edit

@Luksprog : I made following changes :

<SeekBar
    android:id="@+id/seekBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="50dp"
    android:maxHeight="9dp"
    android:minHeight="9dp"
    android:padding="10dp"
    android:max="100"
    android:progressDrawable="@drawable/seekbar_progress"
    android:thumb="@drawable/shine_btn" />

<RelativeLayout
    android:id="@+id/Graph01"
    android:layout_width="wrap_content"
    android:layout_height="200dp"
    android:layout_below="@id/seekBar"
    android:layout_marginTop="50dp"
    android:gravity="bottom" >

    <Button
        android:id="@+id/btnGraph01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"                        
        android:layout_alignParentBottom="true"
        android:background="#99f" />

    <com.example.calci.views.MyTextView
        android:id="@+id/tvGraph01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/btnGraph01" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/Graph02"
    android:layout_width="wrap_content"
    android:layout_height="200dp"
    android:layout_below="@id/seekBar"
android:layout_toRightOf="@id/Graph01"
    android:layout_marginTop="50dp"
    android:gravity="bottom" >

    <Button
        android:id="@+id/btnGraph02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"                        
        android:layout_alignParentBottom="true"
        android:background="#99f" />

    <com.example.calci.views.MyTextView
        android:id="@+id/tvGraph02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/btnGraph02" />
</RelativeLayout>

</RelativeLayout>

and in activity

RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(20,
            2 * progress * 1);
    lp2.setMargins(55, 0, 0, 0);
    btnGraph01.setLayoutParams(lp2);

RelativeLayout.LayoutParams lp3 = new RelativeLayout.LayoutParams(
            new ViewGroup.MarginLayoutParams(20,
                    RelativeLayout.LayoutParams.WRAP_CONTENT));
    lp3.setMargins(55, 0, 0, 30);
    tvGraph01.setLayoutParams(lp3);
    tvGraph01.setTextSize(6);
    tvGraph01.setGravity(Gravity.CENTER);

But TextView is getting displayed inside button… Why it is so?

PLEASE CORRECT ME IF I”M WRONG…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:47:11+00:00Added an answer on June 11, 2026 at 9:47 pm

    First I’m guessing this is related to your previous question. I wouldn’t use weights, instead I would simply use a RelativeLayout with the Buttons attached to the bottom, this way the Buttons will increase in height upwards. Like this:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/parent" >
    
        <SeekBar
            android:id="@+id/sb"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true" 
            android:max="200"/>
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:background="#99cc00"
            android:text="Button"
            android:onClick="test" />
    
        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_toRightOf="@id/button1"
            android:background="#0077cc"
            android:text="Button" />
    
    </RelativeLayout>
    

    Second, I don’t see why you can’t get the desired height. With my code above by using button.getHeight() you’ll get the previous height store(as the new height will not be stored until you get out of onProgressChanged). But this shouldn’t stop you from getting the new height because you are actually calculating that value yourself with :

    progress * 10
    

    Code:

    @Override
    
        public void onProgressChanged(SeekBar seekBar, final int progress,
                            boolean fromUser) {
                        LayoutParams lp = findViewById(R.id.button1).getLayoutParams();
                        lp.width = 50;
                        lp.height = progress * 10;
                        findViewById(R.id.button1).setLayoutParams(lp);
                        Log.e("XZX", "Progress : " + progress + " |Old height : "
                                + findViewById(R.id.button1).getHeight()
                                + "  |New height : " + (progress * 10));
                    }
    

    Edit:
    Your layout file is wrong:

    <RelativeLayout
        android:id="@+id/Graph01"
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:layout_below="@id/seekBar"
        android:layout_marginTop="50dp" >
    
        <Button
            android:id="@+id/btnGraph01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"                        
            android:layout_alignParentBottom="true"
            android:background="#99f" />
    
        <com.example.calci.views.MyTextView
            android:id="@+id/tvGraph01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/btnGraph01" />
    </RelativeLayout>
    

    Now in code there is no need to modify the LayoutParams of tvGraph01, it will follow the Button as it grows/shrinks, also get the current LayoutParams of the Button and modify it instead of creating new ones again and again:

    RelativeLayout.LayoutParams lp2 = (RelativeLayout.LayoutParams)btnGraph01.getLayoutParams();
    lp2.width = 20;
    lp2.height = 2 * progress * 1;
    lp2.setMargins(55, 0, 0, 0); // <= do you really need the margin? what is its purpose?
    btnGraph01.setLayoutParams(lp2);
    tvGraph01.setTextSize(6);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.