如何在 Android 中以编程方式设置 RatingBar 的宽度
How to set width of RatingBar programmatically in Android
我想以编程方式更改我的 RatingBar
样式。任何人都可以帮助我如何改变这种风格,我可以如何填充评级。我给你当前状态的快照:
我的代码:
RatingBar ratingBar = new RatingBar(Review.this);
ratingBar.setStepSize((float) 0.5);
ratingBar.setMax(5);
ratingBar.setRating(Float.parseFloat(rating.get(i)));
运行 时设置视图宽度和高度的步骤
LayoutParams params = null;
Button button = (Button)findViewById(R.id.button);
params = button.getLayoutParams();
params.height = 70;
params.width = 70;
button .setLayoutParams(params);
如果你想使用XML那么上面提到的代码是合适的。
将您的评分栏包裹在 LinearLayout
中,并为其指定高度和宽度 LinearLayout
。
此 LinearLayout
应充当 RatingBar
的父级并将 RatingBar
的宽度和高度设置为 wrap content
。
您也可以使用
RatingBar ratingBar = new RatingBar(context, null, android.R.attr.ratingBarStyleSmall);
可以通过java代码
设置评分栏的小样式
RatingBar ratingBar =
new RatingBar(context, null, android.R.attr.ratingBarStyleSmall);
或使用 xml 文件
<RatingBar
android:id="@+id/ratingBar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:isIndicator="false" />
我想以编程方式更改我的 RatingBar
样式。任何人都可以帮助我如何改变这种风格,我可以如何填充评级。我给你当前状态的快照:
我的代码:
RatingBar ratingBar = new RatingBar(Review.this);
ratingBar.setStepSize((float) 0.5);
ratingBar.setMax(5);
ratingBar.setRating(Float.parseFloat(rating.get(i)));
运行 时设置视图宽度和高度的步骤
LayoutParams params = null;
Button button = (Button)findViewById(R.id.button);
params = button.getLayoutParams();
params.height = 70;
params.width = 70;
button .setLayoutParams(params);
如果你想使用XML那么上面提到的代码是合适的。
将您的评分栏包裹在 LinearLayout
中,并为其指定高度和宽度 LinearLayout
。
此 LinearLayout
应充当 RatingBar
的父级并将 RatingBar
的宽度和高度设置为 wrap content
。
您也可以使用
RatingBar ratingBar = new RatingBar(context, null, android.R.attr.ratingBarStyleSmall);
可以通过java代码
设置评分栏的小样式RatingBar ratingBar =
new RatingBar(context, null, android.R.attr.ratingBarStyleSmall);
或使用 xml 文件
<RatingBar
android:id="@+id/ratingBar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:isIndicator="false" />