Todd-Davies / ProgressWheel

A progress wheel for android, intended for use instead of the standard progress bar.
MIT License
2.64k stars 709 forks source link

Match parent width and height #24

Closed trant closed 9 years ago

trant commented 10 years ago

The ProgressWheel control does not draw when I specify it as :

<com.todddavies.components.progressbar.ProgressWheel android:id="@+id/dialProgressWheel" android:layout_width="match_parent" android:layout_height="match_parent" ProgressWheel:barColor="#FF0000" ProgressWheel:barLength="5dp" ProgressWheel:barWidth="5dp" ProgressWheel:rimColor="#000000" ProgressWheel:rimWidth="10dp" ProgressWheel:text="" ProgressWheel:textColor="#222" ProgressWheel:textSize="14sp" />

golharam commented 10 years ago

I see this too. Have you figured out why? Ill try to look at it myself.

trant commented 10 years ago

I had to make the calculations programatically for achieving that

golharam commented 10 years ago

Want to share your code?

On Tue, Apr 15, 2014 at 11:26 AM, Antonio notifications@github.com wrote:

I had to make the calculations programatically for achieving that

— Reply to this email directly or view it on GitHubhttps://github.com/Todd-Davies/ProgressWheel/issues/24#issuecomment-40495389 .

trant commented 10 years ago
private void updateProgressWheelLayoutParameters(ProgressWheel progressWheel) {

    if (getActivity() == null)
        return;

    Display display = getActivity().getWindowManager().getDefaultDisplay();

    @SuppressWarnings("deprecation")
    int width = display.getWidth();
    @SuppressWarnings("deprecation")
    int height = display.getHeight();

    Resources resources = getResources();

    int progressWheelSize = (width > height ? height / 2 : width / 2) - (int) resources.getDimension(R.dimen.dial_margins);

    progressWheel.setRimWidth((int) resources.getDimension(R.dimen.dial_rim_width));
    progressWheel.setBarWidth((int) resources.getDimension(R.dimen.dial_bar_width));

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(progressWheelSize, progressWheelSize);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    params.addRule(RelativeLayout.BELOW, R.id.dialTitleTextView);

    int marginTop = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, resources.getDisplayMetrics());
    params.setMargins(0, marginTop, 0, 0);

    progressWheel.setLayoutParams(params);
}
trant commented 10 years ago

This is not the best solution still

golharam commented 10 years ago

I discovered the problem...in setupBounds, the call to this.getLayoutParams().width and this.getLayoutParams().height return -1 when the layout_[width|height] parameter is set to match_parent. This throw the rest of the calculations off. I look to fix this.

golharam commented 10 years ago

I just submitted a proper fix as a pull request to this issue.