我是一个Android初学者,我想制作我的自定义ratingBar.
免责声明:这不是重复.因为我读过的所有帖子都询问如何更改星星的颜色以及如何删除笔画.那不是我想要的.我想要中风,并能够改变边框的颜色.
具有透明和黄色的笔划,同时为空,黄色背景和笔划为一半并填充.
我不想使用png.我已经拥有自己的但是它们太小了.如果我只使用XML属性和drawables制作星星,我只是不想让设计师创建新的.
<RatingBar
android:id="@+id/thread_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:numStars="5"
android:progressBackgroundTint="@color/gray"
android:progressTint="@color/gold"
android:rating="2.5"
android:secondaryProgressTint="@color/gray"
android:stepSize="0.5"
style="?android:attr/ratingBarStyleSmall"
/>
Run Code Online (Sandbox Code Playgroud)
我和另一位工程师一起工作.他还在java文件中编写代码
private void setRatingBarStart(RatingBar rating_bar) {
LayerDrawable stars = (LayerDrawable) rating_bar.getProgressDrawable();
stars.getDrawable(2)
.setColorFilter(getResources().getColor(R.color.gold),
PorterDuff.Mode.SRC_ATOP); // for filled stars
stars.getDrawable(1)
.setColorFilter(getResources().getColor(R.color.light_gray),
PorterDuff.Mode.SRC_ATOP); // for half filled stars
stars.getDrawable(0)
.setColorFilter(getResources().getColor(R.color.light_gray),
PorterDuff.Mode.SRC_ATOP); // for empty stars
Run Code Online (Sandbox Code Playgroud)
[所以现在它有一个灰色背景,黄色填充,现在没有中风.
我已经知道如何设置背景透明并使其变黄.我只是不知道如何设置笔触颜色.非常感谢!!!!
有Android SDK 1.1 r1,有没有办法RatingBar用我自己的方法更改小部件类的星形图像?这有可能吗?如果是这样,那怎么样?
谢谢.
android中的RatingBar令人沮丧.
我已经按照/sf/answers/917543581/使用我自己的drawable实现了一个自定义评级栏,但所有的星星都相互叠加,因此最终只显示一颗星.
对于我的生活,我不能弄明白为什么.
编辑:PNG drawable似乎工作正常,但用作矢量drawables的SVG导致此问题
我已经从这个stackoverflow线程实现了一个自定义评级栏,即使我将numStars设置为5或任何其他数字,它也不会显示多个星号
这是守则.
我正在使用矢量绘图用于图像.
main_activity.xml中的 RatingBar
<RatingBar
android:id="@+id/ratingBarValue"
style="@style/Fuel_Indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:numStars="5"
android:stepSize="1.0"
android:max="5" />
Run Code Online (Sandbox Code Playgroud)
Fuel_Indicator样式风格.
<style name="Fuel_Indicator" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/fuel_bar_full</item>
<item name="android:indeterminateDrawable">@drawable/fuel_bar_full</item>
<item name="android:minHeight">23dip</item>
<item name="android:maxHeight">25dip</item>
</style>
Run Code Online (Sandbox Code Playgroud)
该fuel_bar_filled.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/fuel_bar_empty" />
<item android:id="@android:id/secondaryProgress"
android:drawable="@drawable/fuel_bar_empty" />
<item android:id="@android:id/progress"
android:drawable="@drawable/fuel_bar_filled" />
Run Code Online (Sandbox Code Playgroud)
fuel_bar_empty.xml
<selector
xmlns:android="http://schemas.android.com/apk/res/android">`
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_fuel_empty" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_fuel_empty" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_fuel_empty" />
<item android:drawable="@drawable/ic_fuel_empty" />
</selector>
Run Code Online (Sandbox Code Playgroud)
fuel_bar_filled.xml
<selector
xmlns:android="http://schemas.android.com/apk/res/android">`
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_fuel_full" />
<item …Run Code Online (Sandbox Code Playgroud) 有没有人知道是否有可能让RatingBar从右到左而不是从左到右,或者知道怎么做?
也许这是一个愚蠢的问题,但我无法找到一种方法来在TextView的第二行末尾插入小图像.图像始终显示在整个文本视图的右侧,而不是行结束.
我想插入这样的图像:
TextTextTextTextTextTextTextTextTextText
TextTextTextText. <ImageView>
Run Code Online (Sandbox Code Playgroud)
我得到的是:
TextTextTextTextTextTextTextTextTextText <ImageView>
TextTextTextText.
Run Code Online (Sandbox Code Playgroud)
我希望有办法做到这一点.
源:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TESTESTESTESTESTESTESTESTESTESTESTESTES"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/tv"
android:src="@drawable/icon" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 例如,我有一个5星相同的评级栏.当我滑过或触摸任何一颗星时,它会将所有星星从正常变为某种颜色,因为它表示它被评级.
我想要的是,有没有可能我们可以为评级栏的每颗星而不是5颗相同的星星提供5个独特的图像?
像第一颗星是太阳图像,第二颗星是月亮图像,第三颗星是一些方形图像等.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/rl_rating"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" >
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="78dp"
style="@style/CustomRatingBar" />
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我需要像RatingBar这样的东西来选择一年中的几个月,
用户可以选择行进,并将手指朝一个方向移动并选择它.我不能在中间有"未选中"的东西.
在这种情况下,用户选择'Jan'和'Abr'.我没有找到任何针对这种情况的具体内容,因此,我想知道是否有人遇到过此问题,或者我应该手动执行此操作.
谢谢!:)
我ratingBar在使用Java 设置自定义时遇到问题.问题是,setNumStars并且setRating不起作用.虽然我已经将速率设置为0.0f,但我只是在屏幕上看到一个完全标记的星.
这是代码:
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
chapter1 = new Chapter(this);
android.widget.RelativeLayout.LayoutParams layoutParam = new RelativeLayout.LayoutParams(metrics.widthPixels , metrics.heightPixels);
myLayout.addView(chapter1, layoutParam);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
RatingBar ratingBar = new RatingBar(this);
ratingBar.setProgressDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.custom_ratingbar_menu, null));
ratingBar.setNumStars(3);
ratingBar.setRating(0.0f);
layoutParam = new RelativeLayout.LayoutParams(metrics.widthPixels / 6 , metrics.heightPixels / 32);
layoutParam.setMargins(70 + chapter1.getLeft() + wSize * j, 50 + chapter1.getTop() + hSize …Run Code Online (Sandbox Code Playgroud) 我正在创建一个表单,在该表单中我必须在评级栏中放置五个不同的笑脸图标才能获得用户的反馈。
我尝试过,但一次只显示一种类型的图标。
我正在尝试通过更改 style.xml 中的样式
<style name="customRatingBar" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/ratingstars</item>
<item name="android:minHeight">32dip</item>
<item name="android:maxHeight">32dip</item>
</style>
Run Code Online (Sandbox Code Playgroud)
请建议我如何在android中实现这一目标?
提前致谢。
我为RatingBar创建了自定义样式,将样式应用于评级栏时,它仅显示一颗星,并且在RatingBar的属性中,我还定义了起点的大小5,但在运行时它仅显示一星。注意:我正在使用ActionbarActivity,因为我正在显示RatingBar,但是当我仅使用Activity类时,它将显示5星,并且主题也适用于此。所以请帮我解决这个问题。