有谁知道如何使视图颠倒,我有一个水平ProgressBar,我希望它从右到左而不是从左到右从右到左ProgressBar?
回答
使正常进度栏视图的子类和实现onDraw方法旋转绘制它之前的画布:
@Override
protected void onDraw(Canvas canvas) {
canvas.save();
canvas.rotate(180,<CenterX>,<CenterY>);
super.onDraw(canvas);
canvas.restore();
}
这应该有所斩断。
public class inverseSeekBar extends ProgressBar {
public inverseSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public inverseSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public inverseSeekBar(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected synchronized void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
canvas.save();
//now we change the matrix
//We need to rotate around the center of our text
//Otherwise it rotates around the origin, and that's bad.
float py = this.getHeight()/2.0f;
float px = this.getWidth()/2.0f;
canvas.rotate(180, px, py);
//draw the text with the matrix applied.
super.onDraw(canvas);
//restore the old matrix.
canvas.restore();
}}
<com.hlidskialf.android.widget.inverseSeekBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:secondaryProgress="75"
/>
mypackage的:com.test.testProgressBar
太棒了!这工作完美,谢谢! – Tom 2012-04-10 22:42:39
你不需要旋转整个View
。
在my_progress_drawable.xml
只需使用a single xml attribute:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@android:id/background"
android:drawable="@drawable/my_background"/>
<item android:id="@android:id/progress">
<clip
android:drawable="@drawable/my_right_to_left_progress"
android:gravity="right" /> <!-- Clip the image from the RIGHT -->
</item>
</layer-list>
The documentation告诉我们,gravity="right"
做到这一点:
把对象在其容器的右边缘,而不是改变它的大小。当clipOrientation是“水平”时,裁剪发生在drawable的左侧。
请勿覆盖onDraw()
。此实现在不同版本的Android中更稳定。
不幸的是,无法以编程方式设置ClipDrawable
的引力而不调用其constructor。
对于使用
它更容易。你可以简单地调用下面的方法,然后它被旋转并按照你想要的方式工作。
progressBar.setRotation(180);
一个例子:
感谢应该是最好的答案至今 – 2013-12-31 21:41:45
代替 – 2014-04-21 07:22:04
崩溃我的应用程序... – Hamidreza 2014-09-24 08:36:22
因为我是懒惰的我只是这两行添加到seekbar
XML:
android:layoutDirection="rtl"
android:mirrorForRtl="true"
任何缺点这样做呢?
可以翻转使用的scaleX或属性的scaleY
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="-1"/>
这应该是最好的答案 – 2017-05-25 07:35:45
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:layout_margin="8dp"
android:layoutDirection="rtl"
android:progress="80" />
- 1. 从右到左
- 2. 大熊猫:从左到右和从右到左交替排列()从左到右
- 3. 从右到左UILabels
- 4. 从右到左UINavigationController
- 5. 从右到左jframe
- 6. Android:preferencescreen从右到左
- 7. ContextMenu从右到左
- 8. 从左到右从左到右堆叠框用CSS/JS
- 9. 如何从左/右移动到下一个ViewController从左到右
- 10. 禁用ViewPager从右到左滑动从左到右
- 11. Android:从左到右从左到右滑动
- 12. Python从右到左和从左到右打印得很好
- 13. 从左到右telerik combobox从右到左mvc应用程序
- 14. 动画从左到右和从右到左
- 15. CSS转换是从左到右,而不是从右到左
- 16. 从左到右和从右到左的UIImage卷曲
- 17. UITableView区分从左到右和从右到左滑动
- 18. 从左到右语言写成从右到左html
- 19. 如何翻转两个LinearLayout从右到左和从左到右
- 20. 从左到右显示从右到左的菜单子菜单
- 21. 如何从左到右和从右到左动画一个ImageView
- 22. 如何从左到右和从右到左遍历数组?
- 23. 堆叠酒吧从右到左而不是从左到右
- 24. 应用程序interace布局方向从左到右从右到左的语言返回从左到右
- 25. TTrackbar从右至左,而不是从左到右
- 26. 从右到左评估,从左至右链方法
- 27. UIViewAnimationTransitionCurlUp从横向(左和右)方向从右到左
- 28. 图像在android中从左到右从右至左滑动?
- 29. 在45天左右(从左至右)从PHP/Ajax切换到Java
- 30. CSS过渡从左到右工作,右到左不工作
什么语言XML格式的看法?什么平台?什么API? – EboMike 2010-10-07 00:13:00
为什么你需要一个RTL进度条?我看到的所有进度条都是从左到右。 – 2010-10-07 00:19:40
我们只能用伪代码回答伪代码问题......否则请至少指定EboMike的注释要求的内容。 – BoltClock 2010-10-07 00:28:22