android垂直比率条大小问题

android垂直比率条大小问题,android,size,vertical-alignment,android-styles,ratingbar,Android,Size,Vertical Alignment,Android Styles,Ratingbar,我已经垂直排列了分级栏,但这样做,我在管理屏幕上所需大小的分级栏时遇到了问题。我尝试使用提供的图像和默认评级栏进行自定义。但他们都没有帮我 到目前为止,我所做的工作如下: 1) Styles.xml <style name="foodRatingBar" parent="@android:style/Widget.RatingBar"> <item name="android:progressDrawable">@drawable/star_rating_

我已经垂直排列了分级栏,但这样做,我在管理屏幕上所需大小的分级栏时遇到了问题。我尝试使用提供的图像和默认评级栏进行自定义。但他们都没有帮我

到目前为止,我所做的工作如下:

1) Styles.xml

<style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/star_rating_bar_full</item>
        <item name="android:minHeight">48dip</item>
        <item name="android:maxHeight">48dip</item>
    </style>
6) 图像/图标如下所示:

7) 布局,其中我使用了带有样式的分级栏

    <com.navrideclient.widgets.VerticalRatingBar     
    style="@style/foodRatingBar"       
    android:id="@+id/ratingBar_car"  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"  
    android:numStars="5"  
    android:stepSize="1.0" />

<?xml version="1.0" encoding="utf-8"?>

<!-- This is the rating bar drawable that is used to
 show a filled cookie. -->
<selector
xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true"
      android:state_window_focused="true"
      android:drawable="@drawable/star2" />

<item android:state_focused="true"
      android:state_window_focused="true"
      android:drawable="@drawable/star2" />

<item android:state_selected="true"
      android:state_window_focused="true"
      android:drawable="@drawable/star2" />

<item android:drawable="@drawable/star2" />

</selector>
<?xml version="1.0" encoding="utf-8"?>

 <!-- This is the rating bar drawable that is used to
 show a unfilled cookie. -->
<selector
xmlns:android="http://schemas.android.com/apk/res/android">



<item android:state_focused="true"
      android:state_window_focused="true"
      android:drawable="@drawable/star1" />

<item android:state_selected="true"
      android:state_window_focused="true"
      android:drawable="@drawable/star1" />

<item android:drawable="@drawable/star1" />

</selector>
package com.example.ratingbarwidget;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.RatingBar;

public class VerticalRatingBar extends RatingBar {
    private int x, y, z, w;

    @Override
    protected void drawableStateChanged() {
        // TODO Auto-generated method stub
        super.drawableStateChanged();
    }

    public VerticalRatingBar(Context context) {
        super(context);
    }

    public VerticalRatingBar(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public VerticalRatingBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(h, w, oldh, oldw);
        this.x = w;
        this.y = h;
        this.z = oldw;
        this.w = oldh;
    }

    @Override
    protected synchronized void onMeasure(int widthMeasureSpec,
            int heightMeasureSpec) {
        super.onMeasure(heightMeasureSpec, widthMeasureSpec);
        setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
    }

    protected void onDraw(Canvas c) {
        c.rotate(-90);
        c.translate(-getHeight(), 0);
        super.onDraw(c);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (!isEnabled()) {
            return false;
        }

        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:

            setSelected(true);
            setPressed(true);
            break;
        case MotionEvent.ACTION_MOVE:
            setProgress(getMax()
                    - (int) (getMax() * event.getY() / getHeight()));
            onSizeChanged(getWidth(), getHeight(), 0, 0);

            break;
        case MotionEvent.ACTION_UP:
            setSelected(false);
            setPressed(false);
            break;

        case MotionEvent.ACTION_CANCEL:
            break;
        }
        return true;
    }

    @Override
    public synchronized void setProgress(int progress) {

        if (progress >= 0)
            super.setProgress(progress);

        else
            super.setProgress(0);
        onSizeChanged(x, y, z, w);

    }
}
    <com.navrideclient.widgets.VerticalRatingBar     
    style="@style/foodRatingBar"       
    android:id="@+id/ratingBar_car"  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"  
    android:numStars="5"  
    android:stepSize="1.0" />